forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalin.cpp
63 lines (63 loc) · 839 Bytes
/
palin.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
// 2008-01-29
#include <stdio.h>
#include <string.h>
int main()
{
int i,l,t,j,L,U,digit;
bool less,carry;
char K[1000001];
scanf("%d",&t);
for (i=0; i<t; i++)
{
scanf("%s",&K);
l=strlen(K);
less=false;
L=l/2-1;
U=(l+1)/2;
while (L>=0)
{
if (K[L]<K[U])
{
less=false;
break;
}
if (K[L]>K[U])
{
less=true;
break;
}
L--;
U++;
}
if (!less)
{
carry=true;
digit=(l-1)/2;
while (carry&&(digit>=0))
{
K[digit]++;
if (K[digit]==':')
{
K[digit]='0';
carry=true;
}
else
carry=false;
digit--;
}
if (carry) //10000....00001
{
putchar('1');
for (j=0; j<l-1; j++)
putchar('0');
putchar('1');
putchar('\n');
continue;
}
}
for (j=0; j<l/2; j++)
K[l-j-1]=K[j];
printf("%s\n",K);
}
return 0;
}