judge_system 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f7088fd2eef9535682b723698a1ea2259e732ce
4
- data.tar.gz: 7bbbbc92474be94fc9349b656879b32968e77719
3
+ metadata.gz: 0edbafdf0e837695223831d01c6a4046986dc9cb
4
+ data.tar.gz: 02c889a7d4545587dbb50a66bff4b3bb591cd83b
5
5
  SHA512:
6
- metadata.gz: d0af5cf270c9203a7f1b94de22fce005553f452f481df1163cfdde6b165078264cbf1b098ad5e743c5e8b2d208b343af32f619b271c4b5c563f02f8758dab2c9
7
- data.tar.gz: b54ba0085c5de4861196ad0c76b0d6d9dfd933cbcdfc5b348e2d53b640ed749f607b3696732f6b390efc3584989294d64e9b4c1ccc8058b7fe3c27cb9dcd876e
6
+ metadata.gz: e68cef4d56cde0355d253262834d303df0b7285b4ce5ce104f171fdc31dfe9672ffddf1dd4d82ae8e0f56bf6275f613957c46445b5b1255ad749b27a6f8cff1b
7
+ data.tar.gz: 8412483c9cb7b206e155feb45bba324eb2c2372a88da4b2b50f520d57be696506fe841691b08472006575f1dc56df4ed64ae7be3e4e17541ed7684f313660c0a
data/README.md CHANGED
@@ -27,7 +27,7 @@ $ gem install judge_system
27
27
  ```ruby
28
28
  require 'judge_system'
29
29
 
30
- JudgeSystem.judge_result lang(string text), code(string text), answer(string text), input(string text), time-limit(num sec)
30
+ JudgeSystem.judge_result lang: (string text), code: (string text), answer: (string text), stdin: (string text), time: (num sec)
31
31
 
32
32
  #Lang is the extension of languages (example: c is 'c', c++ is 'cpp', ruby is 'rb', java is 'java').
33
33
  #You can't use more than 1M byte code, input, answer.
@@ -39,10 +39,10 @@ example
39
39
  ```ruby
40
40
  require 'judge_system'
41
41
 
42
- p JudgeSystem.judge_result 'rb', "n = gets.to_i\nputs n", "1\n", "1\n", 5 #=> 'AC'
43
- p JudgeSystem.judge_result 'rb', "n = gets.to_i\nputs n", "1\n", "2\n", 5 #=> 'WA'
44
- p JudgeSystem.judge_result 'rb', "n = gets.to_i\nputs n", "1\n", "\n", 0.001 #=> 'TLE'
45
- p JudgeSystem.judge_result 'c', "n = gets.to_i\nputs n", "1\n", "1\n", 5 #=> 'RE'
42
+ p JudgeSystem.judge_result lang: 'rb', code: "n = gets.to_i\nputs n", answer: "1\n", stdin: "1\n", time: 5 #=> 'AC'
43
+ p JudgeSystem.judge_result lang: 'rb', code: "n = gets.to_i\nputs n", answer: "1\n", stdin: "2\n", time: 5 #=> 'WA'
44
+ p JudgeSystem.judge_result lang: 'rb', code: "n = gets.to_i\nputs n", answer: "1\n", stdin: "\n", time: 0.001 #=> 'TLE'
45
+ p JudgeSystem.judge_result lang: 'c', code: "n = gets.to_i\nputs n", answer: "1\n", stdin: "1\n", time: 5 #=> 'RE'
46
46
  ```
47
47
 
48
48
 
@@ -2,22 +2,28 @@
2
2
  #include <fstream>
3
3
  using namespace std;
4
4
 
5
+ char command[1024];
6
+
5
7
  int main(int argc, char const *argv[])
6
8
  {
7
9
  ofstream ofs;
8
- ofs.open("test.c",ios::binary);
10
+ ofs.open("main.c",ios::binary);
9
11
  string buf;
12
+ string splitter="<$><*><$>";
13
+ string time;
10
14
  while(getline(cin,buf)){
11
- if(buf=="<$><*><$><*><$><*><$><*><$><*><$><*><$>")break;
15
+ if(buf==splitter)break;
12
16
  ofs<<buf<<endl;
13
17
  }
14
18
  ofs.close();
15
19
  ofs.open("test.in",ios::binary);
16
20
  while(getline(cin,buf)){
21
+ if(buf==splitter)break;
17
22
  ofs<<buf<<endl;
18
23
  }
19
24
  ofs.close();
20
- system("/opt/wandbox/gcc-head/bin/gcc test.c -o test -O2");
21
- system("/usr/bin/time -f '%U' ./test < test.in");
25
+ cin>>time;
26
+ system("/opt/wandbox/gcc-head/bin/gcc main.c -o main -O2");
27
+ system(("timeout -s 9 " + time + " ./main < test.in").c_str());
22
28
  return 0;
23
- }
29
+ }
@@ -2,22 +2,28 @@
2
2
  #include <fstream>
3
3
  using namespace std;
4
4
 
5
+ char command[1024];
6
+
5
7
  int main(int argc, char const *argv[])
6
8
  {
7
9
  ofstream ofs;
8
- ofs.open("test.cpp",ios::binary);
10
+ ofs.open("main.cpp",ios::binary);
9
11
  string buf;
12
+ string splitter="<$><*><$>";
13
+ string time;
10
14
  while(getline(cin,buf)){
11
- if(buf=="<$><*><$><*><$><*><$><*><$><*><$><*><$>")break;
15
+ if(buf==splitter)break;
12
16
  ofs<<buf<<endl;
13
17
  }
14
18
  ofs.close();
15
19
  ofs.open("test.in",ios::binary);
16
20
  while(getline(cin,buf)){
21
+ if(buf==splitter)break;
17
22
  ofs<<buf<<endl;
18
23
  }
19
24
  ofs.close();
20
- system("/opt/wandbox/gcc-head/bin/g++ test.cpp -o test -O2");
21
- system("/usr/bin/time -f '%U' ./test < test.in");
25
+ cin>>time;
26
+ system("/opt/wandbox/gcc-head/bin/g++ main.cpp -o main -O2");
27
+ system(("timeout -s 9 " + time + " ./main < test.in").c_str());
22
28
  return 0;
23
29
  }
@@ -5,7 +5,7 @@ using namespace std;
5
5
  int main(int argc, char const *argv[])
6
6
  {
7
7
  ofstream ofs;
8
- ofs.open("test.java",ios::binary);
8
+ ofs.open("Main.java",ios::binary);
9
9
  string buf;
10
10
  while(getline(cin,buf)){
11
11
  if(buf=="<$><*><$><*><$><*><$><*><$><*><$><*><$>")break;
@@ -17,7 +17,62 @@ int main(int argc, char const *argv[])
17
17
  ofs<<buf<<endl;
18
18
  }
19
19
  ofs.close();
20
- system("/opt/wandbox/openjdk-head/bin/javac test.java");
21
- system("/usr/bin/time -f '%U' /opt/wandbox/openjdk-head/bin/java test < test.in");
20
+ system("/opt/wandbox/openjdk-head/bin/javac Main.java");
21
+ system("/usr/bin/time -f '%U' /opt/wandbox/openjdk-head/bin/java Main < test.in");
22
22
  return 0;
23
- }
23
+ }
24
+
25
+
26
+
27
+
28
+ /*import java.util.*;
29
+ import java.io.*;
30
+ class Career{
31
+ public static void main(String[] args){
32
+
33
+ Scanner sc = null;
34
+ File code = null;
35
+ PrintWriter pw = null;
36
+ File stdin = null;
37
+ PrintWriter pw2 = null;
38
+ String str = null;
39
+ BufferedReader br = null;
40
+ Process compile = null;
41
+ Runtime r = null;
42
+ InputStream run = null;
43
+
44
+ try{
45
+ sc = new Scanner(System.in);
46
+ code = new File("Main.java");
47
+ stdin = new File("test.in");
48
+ pw = new PrintWriter(new BufferedWriter(new FileWriter(code)));
49
+ pw2 = new PrintWriter(new BufferedWriter(new FileWriter(stdin)));
50
+ while(true){
51
+ str = sc.next();
52
+ if(str.equals("<$><*><$><*><$><*><$><*><$><*><$><*><$>")){
53
+ break;
54
+ }
55
+ pw.println(str);
56
+ }
57
+ code.createNewFile();
58
+
59
+ while(sc.hasNext()){
60
+ str = sc.next();
61
+ pw2.println(str);
62
+ }
63
+ stdin.createNewFile();
64
+
65
+ r = Runtime.getRuntime();
66
+ compile = r.exec("/opt/wandbox/openjdk-head/bin/javac Main.java");
67
+ compile.waitFor();
68
+ run = r.exec("/usr/bin/time -f '%U' /opt/wandbox/openjdk-head/bin/java Main < test.in").getInputStream();
69
+ br = new BufferedReader(new InputStreamReader(run));
70
+ String line;
71
+ while ((line = br.readLine()) != null) {
72
+ System.out.println(line);
73
+ }
74
+ }catch(Exception e ){
75
+ e.printStackTrace();
76
+ }
77
+ }
78
+ }*/
@@ -2,21 +2,27 @@
2
2
  #include <fstream>
3
3
  using namespace std;
4
4
 
5
+ char command[1024];
6
+
5
7
  int main(int argc, char const *argv[])
6
8
  {
7
9
  ofstream ofs;
8
- ofs.open("test.rb",ios::binary);
10
+ ofs.open("main.rb",ios::binary);
9
11
  string buf;
12
+ string splitter="<$><*><$>";
13
+ string time;
10
14
  while(getline(cin,buf)){
11
- if(buf=="<$><*><$><*><$><*><$><*><$><*><$><*><$>")break;
15
+ if(buf==splitter)break;
12
16
  ofs<<buf<<endl;
13
17
  }
14
18
  ofs.close();
15
19
  ofs.open("test.in",ios::binary);
16
20
  while(getline(cin,buf)){
21
+ if(buf==splitter)break;
17
22
  ofs<<buf<<endl;
18
23
  }
19
24
  ofs.close();
20
- system("/usr/bin/time -f '%U' /opt/wandbox/ruby-head/bin/ruby test.rb < test.in");
25
+ cin>>time;
26
+ system(("timeout -s 9 " + time + " /opt/wandbox/ruby-head/bin/ruby main.rb < test.in").c_str());
21
27
  return 0;
22
28
  }
data/lib/judge_system.rb CHANGED
@@ -30,7 +30,7 @@ module JudgeSystem
30
30
  response = http.request(request)
31
31
  JSON.parse(response.body)
32
32
  end
33
-
33
+
34
34
  end
35
35
  module_function :compile
36
36
  end
@@ -41,19 +41,21 @@ module JudgeSystem
41
41
  path = File.expand_path('../', __FILE__ )
42
42
  sys = File.open("#{path}/compile_systems/#{lang}_system.cpp", "r").read
43
43
  data = nil
44
- stdin = code + "\n<$><*><$><*><$><*><$><*><$><*><$><*><$>\n" + input
44
+ spliter = "\n<$><*><$>\n"
45
+ stdin = code + spliter + input + spliter + time.to_s
45
46
  begin
46
- data = Web.compile({ compiler: "gcc-head", code: sys, stdin: stdin })
47
+ p data = Web.compile({ compiler: "gcc-head", code: sys, stdin: stdin })
47
48
  rescue
48
49
  return 'RE'
49
50
  end
50
- runtime = data["program_error"].split("\n")[-1].to_f
51
- if data["program_output"] == nil
52
- return 'RE'
53
- elsif runtime > time
54
- return "TLE"
51
+ error = data["program_error"]
52
+ result = data["program_output"]
53
+ if error == "Killed\n"
54
+ return 'TLE'
55
+ elsif result == nil && error
56
+ return "RE"
55
57
  else
56
- return data["program_output"]
58
+ return result
57
59
  end
58
60
  end
59
61
  module_function :run
@@ -1,3 +1,3 @@
1
1
  module JudgeSystem
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshifumi Kiyono
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler