-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem.cpp
More file actions
76 lines (64 loc) · 1.46 KB
/
problem.cpp
File metadata and controls
76 lines (64 loc) · 1.46 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
#include <bits/stdc++.h>
#include <signal.h>
typedef long long ll;
using namespace std;
// #include <
bool writeSolution = false;
int id = -1;
int score = 0;
char *file_path;
char *output_path;
void print_solution(FILE *out);
void sol_requested(int signal) {
writeSolution = true;
}
void write_solution_force() {
stringstream ss;
ss << output_path;
ss << setw(15) << setfill('0') << score;
ss << "_id" << id << ".txt";
FILE *output = fopen(ss.str().c_str(), "w");
print_solution(output);
fclose(output);
}
__attribute__((always_inline))
inline void write_solution(bool force = false) {
if (writeSolution || force) {
writeSolution = false;
write_solution_force();
}
}
//////////////////////// END TEMPLATE ////////////////////////
ll test = 0;
void read_input(FILE *in) {
fscanf(in, "%lld", &test);
}
void print_solution(FILE *out) {
// Write sol
fprintf(out, "%lld\n", test);
}
int main(int argc, char* argv[])
{
if (argc > 3) {
id = atoi(argv[3]);
if (id == 0 && argv[3][0] != '0') id = -1;
}
if (argc < 3) {
cout << "Input or output files missing" << endl;
return 1;
}
else {
file_path = argv[1];
output_path = argv[2];
}
signal(SIGUSR1, sol_requested);
FILE *input = fopen(file_path, "r");
read_input(input);
fclose(input);
while (true) {
test++;
score = test;
write_solution();
}
return 0;
}