This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dp.cpp
103 lines (90 loc) · 3.2 KB
/
dp.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// dp <problemid> [generateCommand [checkerPath]]
#include <cstdio>
#include <string>
#include <cstdlib>
#include <direct.h>
using namespace std;
string quote(const string & s)
{
return "\"" + s + "\"";
}
string problemid, generateCommand, checkerPath;
bool hasChecker;
int main(int argc, char* argv[])
{
if (argc < 2 || argc > 4)
{
puts("dp <problemid> [generateCommand [checkerPath]]");
return 0;
}
problemid = argv[1];
string pwd = getcwd(NULL, 0);
if (argc >= 3) generateCommand = argv[2];
else
{
if (system(("compile " + quote(pwd + "\\problems\\" + problemid + "\\gen")).c_str()))
{
puts("Generator Compile Error!");
return 1;
}
generateCommand = "call " + quote(pwd + "\\problems\\" + problemid + "\\gen.exe") +
" > " + quote(pwd + "\\problems\\" + problemid + "\\dp.in");
}
if (argc >= 4)
{
hasChecker = true;
checkerPath = argv[3];
if (checkerPath == "1")
{
if (system(("compile " + quote(pwd + "\\problems\\" + problemid + "\\checker") + " " + quote("-I " + pwd)).c_str()))
{
puts("Checker Compile Error!");
return 1;
}
checkerPath = pwd + "\\problems\\" + problemid + "\\checker.exe";
}
}
if (system(("compile " + quote(pwd + "\\problems\\" + problemid + "\\" + problemid)).c_str()))
{
puts("Source File Compile Error!");
return 1;
}
if (system(("compile " + quote(pwd + "\\problems\\" + problemid + "\\std")).c_str()))
{
puts("Std Compile Error!");
return 1;
}
while (1)
{
system(generateCommand.c_str());
system(("call " + quote(pwd + "\\problems\\" + problemid + "\\" + problemid)
+ " < " + quote(pwd + "\\problems\\" + problemid + "\\dp.in")
+ " > " + quote(pwd + "\\problems\\" + problemid + "\\" + problemid + ".out")).c_str());
system(("call " + quote(pwd + "\\problems\\" + problemid + "\\std")
+ " < " + quote(pwd + "\\problems\\" + problemid + "\\dp.in")
+ " > " + quote(pwd + "\\problems\\" + problemid + "\\std.out")).c_str());
if (hasChecker)
{
if (system((quote(checkerPath) + " " + quote(pwd + "\\problems\\" + problemid + "\\dp.in")
+ " " + quote(pwd + "\\problems\\" + problemid + "\\" + problemid + ".out")
+ " " + quote(pwd + "\\problems\\" + problemid + "\\std.out")).c_str()))
{
puts("Crashed!");
break;
}
}
else
{
if (system(("fc /W " + quote(pwd + "\\problems\\" + problemid + "\\" + problemid + ".out")
+ " " + quote(pwd + "\\problems\\" + problemid + "\\std.out")).c_str()))
{
puts("Crashed!");
break;
}
}
}
system(quote(pwd + "\\problems\\" + problemid + "\\dp.in").c_str());
system(quote(pwd + "\\problems\\" + problemid + "\\std.out").c_str());
system(quote(pwd + "\\problems\\" + problemid + "\\" + problemid + ".out").c_str());
return 0;
}