forked from cacophonix/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANARC08B.cpp
77 lines (72 loc) · 1.11 KB
/
ANARC08B.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
/*
USER: zobayer
TASK: ANARC08B
ALGO: ad-hoc
*/
#include <stdio.h>
#include <string.h>
char bit[10][10] = {
"063", "010", "093", "079", "106", "103", "119", "011", "127", "107"
};
inline int getnum(int code)
{
switch(code)
{
case 63: return 0;
case 10: return 1;
case 93: return 2;
case 79: return 3;
case 106: return 4;
case 103: return 5;
case 119: return 6;
case 11: return 7;
case 127: return 8;
case 107: return 9;
}
return -1;
}
void getres(char *res, int n)
{
char temp[50] = "0";
int k = 0;
res[0] = 0;
while(n)
{
temp[k++] = n%10+'0';
n /= 10;
}
if(!k) k++;
temp[k] = 0;
for(--k; k>=0; k--)
strcat(res, bit[temp[k]-'0']);
}
int main()
{
int i, j, k, a, n[3];
char input[1000], res[1000];
while(scanf("%s", input)==1)
{
if(!strcmp(input,"BYE")) break;
a = n[0] = n[1] = k = 0;
for(i=0; input[i]!='='; )
{
if(input[i]=='+')
{
k++;
i++;
}
else
{
for(j=i; j<3+i; j++)
a = a*10 + input[j]-'0';
n[k] = n[k]*10 + getnum(a);
a = 0;
i += 3;
}
}
n[2] = n[0] + n[1];
getres(res, n[2]);
printf("%s%s\n", input, res);
}
return 0;
}