-
Notifications
You must be signed in to change notification settings - Fork 0
/
10. PALIN.cpp
87 lines (76 loc) · 1.75 KB
/
10. 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
#define max2(a, b) (((a) > (b)) ? (a) : (b))
#define min2(a, b) (((a) > (b)) ? (b) : (a))
#define abs(a) (((a) > 0) ? (a) : (-(a)))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const int INF = 0x3f3f3f3f;
typedef long long ll;
int main()
{
int t;
while(t--)
{
string s;
cin>>s;
int len = s.length();
int mid = len / 2;
int before = mid - 1, after = mid;
if(len % 2)
{
after++;
}
bool isLeftGreater = true;
int temp = 0;
for(int i = 0; i < mid; i++)
{
if(s[before -i] == s[after + i])
{
temp++;
}
if(s[before -i] < s[after + i])
{
isLeftGreater = false;
break;
}
}
if(temp == mid) isLeftGreater = false;
temp = 0;
if(!isLeftGreater)
{
if(len % 2)
{
before++;
}
temp = before;
int carry = 0
while((s[temp] = (s[temp] - '0' + carry) + '0')== '9')
{
s[temp] == '0';
carry = 1;
}
}
if(len % 2)
{
if(s[mid] > s[mid + 2])
{
for(int i = 0; i < mid + 2; i++)
{
cout<<s[i];
}
reverse(s, s + mid + 1);
for(int i = 0; i < mid + 1; i++)
{
cout<<s[i];
}
cout<<endl;
continue;
}
else
{
}
}
}
return 0;
}