forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1131(AC).cpp
72 lines (66 loc) · 1.28 KB
/
POJ1131(AC).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
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAXN = 2000;
int a[MAXN];
int b[MAXN];
char s[MAXN];
int f[10][4] = {
{0, 0, 0, 0}, {0, 1, 2, 5}, {0, 2, 5, 0}, {0, 3, 7, 5}, {0, 5, 0, 0},
{0, 6, 2, 5}, {0, 7, 5, 0}, {0, 8, 7, 5}, {1, 0, 0, 0}, {1, 1, 2, 5}
};
int main()
{
int len, i, j;
while(scanf("%s", s) == 1){
memset(a, 0, MAXN * sizeof(int));
memset(b, 0, MAXN * sizeof(int));
if(s[0] == '1'){
printf("%s [8] = 1 [10]\n", s);
continue;
}
len = strlen(s);
i = len - 1;
j = 0;
while(s[i] != '.'){
memset(b, 0, MAXN * sizeof(int));
for(j = 0; j < MAXN - 3; ++j){
if(a[j] > 0){
b[j] += f[a[j]][0];
b[j + 1] += f[a[j]][1];
b[j + 2] += f[a[j]][2];
b[j + 3] += f[a[j]][3];
}else{
continue;
}
}
b[0] += f[s[i] - '0'][1];
b[1] += f[s[i] - '0'][2];
b[2] += f[s[i] - '0'][3];
for(j = MAXN - 1; j > 0; --j){
b[j - 1] += b[j] / 10;
b[j] %= 10;
}
b[0] %= 10;
memcpy(a, b, MAXN * sizeof(int));
--i;
}
printf("%s [8] = ", s);
j = MAXN - 1;
while(j >= 0 && a[j] == 0){
--j;
}
if(j >= 0){
printf("0.");
for(i = 0; i <= j; ++i){
printf("%d", a[i]);
}
}else{
printf("0");
}
printf(" [10]\n");
}
return 0;
}