-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
169 lines (107 loc) · 2.88 KB
/
Copy pathmain.cpp
File metadata and controls
169 lines (107 loc) · 2.88 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
string preparse(string);
void pretest(string problem, string temp);
int main()
{
string page_url = "curl http://codeforces.com/problemset/problem/";
string problem_code;
cout << "Enter the problem code" << endl;
cin >> problem_code ;
string problem = problem_code;
problem_code.insert(3, 1, '/');
cout << problem_code << endl;
page_url = page_url + problem_code + " > source.txt";
char page_url_char[70];
for(int i=0; i < page_url.size() ; i++) page_url_char[i] = page_url[i];
page_url_char[page_url.size()] = '\0';
//system(page_url_char);
//system("subl source.txt");
ifstream source_of_page("source.txt");
string lines;
string inputs;
size_t pos, endpos;
while(source_of_page.good())
{
getline(source_of_page,lines); // get line from file
pos=lines.find("<pre>"); // search
if(pos!=string::npos) // string::npos is returned if string is not found
{
endpos = lines.rfind("</pre>");
inputs = lines.substr(pos, endpos-pos+6);
cout <<"Found!\n";
cout << pos << endl;
break;
}
}
cout << inputs << endl;
ofstream outputs("new_source.txt");
outputs << inputs;
outputs.close();
source_of_page.close();
ifstream source_text("new_source.txt");
string inputs2;
getline(source_text, inputs2);
source_text.close();
//cout << inputs << endl;
string temp;
int pos2=0, endpos2=0;
int binar=0; //For writing "Input" & "Output"
ofstream ioputs("ioputs.txt");
while(true)
{
pos2 = inputs2.find("<pre>", pos2) + 5;
endpos2 = inputs2.find("</pre>", endpos2+1);
if(endpos2 == string::npos) break;
temp = inputs2.substr(pos2, endpos2-pos2);
//cout << temp << endl;
temp = preparse(temp);
if(binar%2 == 0 )
{
ioputs << "Input\n";
ofstream test_input("testcase.txt");
test_input << temp;
}
else
{
ioputs << "Output\n";
pretest(problem,temp);
}
binar++;
ioputs << temp;
}
//pretest(problem);
return 0;
}
string preparse(string temp)
{
int pos, endpos;
while(true)
{
pos = temp.find("<br />");
if(pos == string::npos) break;
temp.replace(pos, 6, "\n");
}
cout << temp << endl;
return temp;
}
void pretest(string problem, string temp)
{
problem = "g++ " + problem + ".cpp";
char prob[12];
for(int i=0; i<problem.size(); i++) prob[i] = problem[i];
prob[problem.size()] = '\0';
system(prob);
system("./a.out < testcase.txt > test_result.txt"); //send input from textcase.txt to ./a.out
ifstream test_result("test_result.txt"); //and saving ouput in test_result.txt
string output;
getline(test_result, output);
temp.pop_back();
cout << output.size() << endl;
cout << temp.size() << endl;
if(output.compare(temp) == 0) cout << "PASSED!" << endl;
else cout << "FAILED!" << endl;
}