forked from cafe-grader-team/cafe-grader-judge-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnew_problem
executable file
·73 lines (56 loc) · 1.58 KB
/
new_problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby
# new_problem:
# * creates a directory for a problem in the current directory,
# * create standard testcase config file
require 'erb'
def process_options(options)
i = 2
while i<ARGV.length
if ARGV[i]=='-t'
options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1
i += 1
end
if ARGV[i]=='-m'
options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1
i += 1
end
i += 1
end
end
puts "This script is out of dated, shall be fixed soon"
puts "Right now, you can create raw_ev and import"
exit(0)
GRADER_DIR = File.dirname(__FILE__)
# print usage
if ARGV.length < 2
puts <<USAGE
using: new_problem problem number_of_testcase [options]
* creates a directory for a problem in the current directory,
* create standard testcase config file
* options: -t time-limit (in seconds)
-m mem-limit (in MB)
USAGE
exit(127)
end
# processing arguments
problem = ARGV[0]
num_testcases = ARGV[1].to_i
options = {:time_limit => 1, :mem_limit => 16}
process_options(options)
# start working
puts "creating directories"
system("mkdir #{problem}")
system("mkdir #{problem}/script")
system("mkdir #{problem}/test_cases")
puts "creating testcases directories"
1.upto(num_testcases) do |i|
system("mkdir #{problem}/test_cases/#{i}")
end
# generating all_tests.cfg
puts "generating testcase config file"
template = File.open(File.dirname(__FILE__) + "/templates/all_tests.cfg.erb").read
all_test_cfg = ERB.new(template)
cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w")
cfg_file.puts all_test_cfg.result
cfg_file.close
puts "done"