-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCJ2019_A_ForegoneSolution.cpp
111 lines (95 loc) · 2.15 KB
/
GCJ2019_A_ForegoneSolution.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
104
105
106
107
108
109
110
111
#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
//#include <bitset>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;
static FILE *fin, *fout;
#define LOCAL_TEST
class ProblemSolver {
public:
// DATA
string input, a, b;
size_t st;
public:
void solve(int problemIdx) {
size_t n = input.size();
st = n;
for (size_t i=0; i<n; i++)
{
int d = input[i] - '0';
if (d == 4)
{
a.push_back('3');
b.push_back('1');
if (st == n)
{
st = i;
}
}
else
{
a.push_back(input[i]);
if (st != n)
{
b.push_back('0');
}
}
}
if (b.size() == 0)
{
b.push_back('0');
}
}
void read(int problemIdx) {
input.clear();
a.clear();
b.clear();
char buffer[128];
fgets(buffer, 128, fin);
for (size_t i=0; buffer[i] != '\0'; i++)
{
if (buffer[i] != '\n')
input.push_back(buffer[i]);
}
}
void write(int problemIdx) {
fprintf(fout, "%s %s\n", a.c_str(), b.c_str());
}
};
int main(int, char**) {
#ifdef LOCAL_TEST
fin = fopen("/home/alin/projects/contests/input.txt", "rt");
fout = stdout;
#else
//fin = fopen("input.txt", "rt");
//fout = fopen("output.txt", "wt");
fin = stdin;
fout = stdout;
#endif
int problemCount;
ProblemSolver problemSolver;
fscanf(fin, "%d\n", &problemCount);
for(int problemIdx = 1; problemIdx <= problemCount; problemIdx++) {
problemSolver.read(problemIdx);
problemSolver.solve(problemIdx);
fprintf(fout, "Case #%d: ", problemIdx);
problemSolver.write(problemIdx);
}
fclose(fin);
fclose(fout);
return 0;
}