forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10023.cpp
84 lines (81 loc) · 1.16 KB
/
10023.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
#include <bits/stdc++.h>
using namespace std;
static int N[505], O[1005], T[1005];
static char in[1005], cp[1005];
int main()
{
int t, first = 1, len, n, i, i2, j, k;
scanf("%d", &t);
getchar();
while (t--)
{
getchar();
gets(in);
len = strlen(in);
if (len & 1)
{
for (i = len; i > 0; i--)
{
in[i] = in[i - 1];
}
in[0] = '0', in[++len] = '\0';
}
n = len >> 1;
for (i = 0; i < len; i++)
{
O[i] = 0;
}
for (i = 0; i < len; i++)
{
cp[i] = '0';
}
cp[len] = '\0';
for (i = 1; i <= n; i++)
{
i2 = i * 2;
for (j = 0; j < i2; j++)
{
T[j] = O[j];
}
for (N[i - 1] = 0; N[i - 1] < 10; N[i - 1]++)
{
for (j = 0; j < i; j++)
{
T[i + j] += 2 * N[j];
}
T[i2 - 1]++;
for (j = i2 - 1; j > 0; j--)
{
T[j - 1] += T[j] / 10;
T[j] %= 10;
}
for (j = 0; j < i2; j++)
{
cp[j] = T[j] + '0';
}
if (strncmp(cp, in, i2) > 0)
{
break;
}
for (j = 0; j < i2; j++)
{
O[j] = T[j];
}
}
}
if (first)
{
first = 0;
}
else
{
printf("\n");
}
for (i = 0; i < n; i++)
{
printf("%d", N[i]);
}
printf("\n");
}
return 0;
}