Skip to content

Commit e7019e2

Browse files
committed
holla
Merge branch 'master' of https://github.com/TheCodeCamp/CodeCamp
2 parents 26a5627 + 5cac727 commit e7019e2

29 files changed

Lines changed: 281 additions & 154 deletions

File tree

contest/models/problem/problem.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@
4747
},
4848
"author":{
4949
"type":"string"
50+
},
51+
"testCaseInput":{
52+
"type":"string",
53+
"default":""
54+
},
55+
"testCaseOutput":{
56+
"type":"string"
5057
}
5158
}
File renamed without changes.
Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,51 @@ const compileProblem= async (lang , filename)=>{
1616
var cmd,file;
1717
switch(lang){
1818
case "c":
19-
file = path.basename(filename ,path.extname(filename)) +".out "
20-
cmd="cd result && gcc -o " + file + " " + path.join(__dirname,"result/"+filename);
19+
file = path.basename(filename,'.c') +".out ";
20+
cmd="cd "+ path.join(__dirname,"result/source") && "gcc -o " +path.join(__dirname,"result/binary/") +file + " " + filename;
2121
break;
2222
case "c++":
2323
case "cpp":
24-
file = path.basename(filename ,path.extname(filename)) +".out "
25-
cmd = "cd result && g++ -o " + file + " " + path.join(__dirname,"result/"+filename);
24+
file = path.basename(filename,'.cpp')+".out";
25+
console.log(file)
26+
cmd="cd "+ path.join(__dirname,"result/source") + " && g++ -o " + path.join(__dirname,"result/binary/")+file + " " +filename;
2627
break;
2728
case "java":
28-
file = path.basename(filename ,path.extname(filename))
29-
cmd = "cd result && javac "+ path.join(__dirname,"result/"+filename)
30-
}
31-
32-
29+
file = path.basename(filename,'.java')
30+
cmd ="cd "+ path.join(__dirname,"result/source") + " && javac -d " + path.join(__dirname,"result/binary/") +" " +filename;
31+
}
3332
return new Promise((resolve,reject)=>{
3433
exec(cmd, (error, stdout, stderr) => {
3534
if (error) {
3635
//console.error(`${error}`);
37-
3836
reject(error);
3937
}
40-
console.log( cmd)
4138
resolve(file)
4239
});
4340
})
4441
}
4542

4643
//Run Compiled if okay the check result
4744

48-
async function runCompiled(lang,file){
45+
async function runCompiled(lang,file,contest,problem){
4946

5047
var cmd;
5148
switch(lang){
5249
case "c":
53-
cmd="cd result && ./" + file + " <'input.txt'";
50+
cmd= "cd "+ path.join(__dirname,"result/binary") + " && ./" + file + " <"+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt";
5451
break;
5552
case "c++":
56-
case "cpp":
57-
cmd = "cd result && ./" + file +" <'input.txt'";
53+
case "cpp":
54+
cmd = "cd "+ path.join(__dirname,"result/binary") + " && ./" + file +" <"+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt";
5855
break;
5956
case "java":
60-
cmd = "cd result && java " + file +" <'input.txt'";
57+
cmd = "cd "+ path.join(__dirname,"result") + " && java " + file +" <"+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt";
6158
}
6259

6360
return new Promise((resolve,reject)=>{
6461
exec(cmd, {timeout:100000,maxBuffer:2147483647,encoding:'utf8'},(error, stdout, stderr) => {
65-
if (error) {
62+
if (error) {
63+
//console.log(error)
6664
reject(error);
6765
}
6866
var res=stdout;
@@ -84,25 +82,25 @@ const checkResult=async (UserResult,serverResult)=>{
8482
}
8583
})
8684
}
87-
const serverResult = async ()=>{
85+
const serverResult = async (contest,problem)=>{
8886
return new Promise((resolve,reject)=>{
89-
var buf= fs.readFileSync(path.join(__dirname,'result/result.txt'),'utf8');
87+
var buf= fs.readFileSync(path.join(__dirname,"result/output/"+contest+"/"+problem+".txt"),'utf8');
9088
resolve(buf)
9189
}).catch((e)=>{
9290
console.log(e)
9391
})
9492
}
9593

9694
const base64tofile = async (base64,lang)=>{
97-
var fileout=new Buffer(base64,'base64').toString('ascii');
98-
var filename = "Solution.";
95+
const fileout=new Buffer(base64,'base64').toString('ascii');
96+
let filename = 'Solution.';
9997
if(lang=='C++'|| lang == 'c++'){
10098
filename+='cpp';
10199
}else{
102100
filename+=lang;
103101
}
104102
return new Promise((resolve,reject)=>{
105-
fs.writeFile(path.join(__dirname ,'result/'+filename),fileout, function(err) {
103+
fs.writeFile(path.join(__dirname ,'result/source/'+filename),fileout, function(err) {
106104
if(err) {
107105
reject('Can not write file');
108106
}
@@ -111,26 +109,15 @@ const base64tofile = async (base64,lang)=>{
111109
})
112110
}
113111

114-
async function compileAndRunProblem(lang , description){
112+
async function compileAndRunProblem(contest,problem,id,lang ,description){
115113
const filename= await base64tofile(description,lang);
116114
const file = await compileProblem(lang,filename);
117-
const result= await runCompiled(lang,file);
118-
const serverRes= await serverResult();
119-
console.log(serverRes)
115+
console.log(contest,problem)
116+
const result= await runCompiled(lang,file,contest,problem);
117+
const serverRes= await serverResult(contest,problem);
120118
const Result = await checkResult(result,serverRes);
121-
//console.log(Result)
119+
console.log(Result)
122120
return Result;
123121

124122
}
125-
//base64tofile('dmFyIHBhdGggPSByZXF1aXJlKCdwYXRoJyk7DQp2YXIgZnMgPSByZXF1aXJlKCdmcycpOw==','C');
126-
//compileAndRunProblem('C','I2luY2x1ZGU8c3RkaW8uaD4NCmludCBtYWluKCl7DQoJcHJpbnRmKCJoZWxsbyB3b3JsZCIpOw0KfQ0K')
127-
128-
/*compileProblem('C','test.c')
129-
.then((file)=>{
130-
runCompiled('C',file)})
131-
.then((res)=>{
132-
checkResult(res,'abcd')
133-
})
134-
*/
135-
136123
module.exports = {compileAndRunProblem,compileProblem,runCompiled,base64tofile,serverResult,checkResult}

judge/result/binary/Test.class

2.12 KB
Binary file not shown.

judge/result/binary/test.out

13.7 KB
Binary file not shown.

judge/result/input/MARH1/ab2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fdhdjdjd

judge/result/input/MARH1/ab22.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fdhdjdjd

0 commit comments

Comments
 (0)