-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalin.cpp
More file actions
55 lines (45 loc) · 663 Bytes
/
palin.cpp
File metadata and controls
55 lines (45 loc) · 663 Bytes
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
#include <bits/stdc++.h>
#include <cstring>
//#include <vector.h>
using namespace std;
void palin(char arr[])
{
long length=strlen(arr);
long index1= (length-1)/2;
long index2= length/2;
int change=0;
while(index1>=0){
if(arr[index1]<arr[index2] && change==0 )
{
arr[index1]+=1;
arr[index2]=arr[index1];
change++;
index1--;
index2++;
}
else if(arr[index1]>arr[index2] || change>0)
{
arr[index2]=arr[index1];
change++;
}
else
{
index1--;
index2++;
}
}
printf("%s",arr);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
char arr[1000000];
scanf("%s",arr);
palin(arr);
cout<<endl;
}
return 0;
}