#include<stdio.h>
#include<string.h>
char increment(char ch){
if(ch==‘1’){
ch=‘2’;
return ch;
}
if(ch==‘2’){
ch=‘3’;
return ch;
}
if(ch==‘3’){
ch=‘4’;
return ch;
}
if(ch==‘4’){
ch=‘5’;
return ch;
}
if(ch==‘5’){
ch=‘6’;
return ch;
}
if(ch==‘6’){
ch=‘7’;
return ch;
}
if(ch==‘7’){
ch=‘8’;
return ch;
}
if(ch==‘8’){
ch=‘9’;
return ch;
}
if(ch==‘0’){
ch=‘1’;
return ch;
}
return ch;
}
int main()
{
long int size,i,firstplace=0,changeplace;
long int lowerbound,upperbound;
scanf("%ld",&size);
char str[size][100000];
for( i=0;i<size;i++)
scanf(" %s",str[i]);
for( i=0;i<size;i++){
if(strlen(str[i])==1){
if(str[i][0]!='9')
str[i][0]=increment(str[i][0]);
else{
str[i][0]='1';
str[i][1]='1';
}
}
else if(str[i][ strlen(str[i])-1 ]!='9')
str[i][strlen(str[i])-1] = increment(str[i][strlen(str[i])-1]);
else if(str[i][ strlen(str[i])-1 ]=='9'){
changeplace=strlen(str[i])-1;
while(str[i][ changeplace ]=='9'){
str[i][changeplace]='0';
if(changeplace==0)
break;
else
changeplace--;
}
if(changeplace!=0)
str[i][changeplace]=increment(str[i][changeplace]);
else{
str[i][0]='1';
str[i][strlen(str[i])]='0';
str[i][strlen(str[i])+1]='\0';
}
}
if(strlen(str[i])>1)
{
firstplace=0;
while(str[i][firstplace]=='0')
firstplace++;
lowerbound=firstplace;
upperbound=strlen(str[i])-1;
while( ( lowerbound < upperbound ) && ( lowerbound < (( lowerbound + upperbound )+1)/2-1 ) ){
str[i][upperbound]=str[i][lowerbound];
upperbound--;
lowerbound++;
}
if((( lowerbound + upperbound )+1)%2==0){
if( str[i][lowerbound] < str[i][upperbound] ){
str[i][lowerbound] = increment(str[i][lowerbound]);
str[i][upperbound] = str[i][lowerbound];
}
else
str[i][upperbound]=str[i][lowerbound];
}
else if((( lowerbound + upperbound )+1)%2!=0)
{
if(str[i][lowerbound+1]!='9')
{
if( str[i][lowerbound] < str[i][upperbound] ){
str[i][upperbound] = str[i][lowerbound];
str[i][lowerbound+1] = increment(str[i][lowerbound+1]);
}
else
str[i][upperbound]=str[i][lowerbound];
}
else
{
if( str[i][lowerbound] < str[i][upperbound] ){
str[i][lowerbound+1]='0';
str[i][lowerbound]=increment(str[i][lowerbound]);
str[i][upperbound]=str[i][lowerbound];
}
else
str[i][upperbound]=str[i][lowerbound];
}
}
}
for(int j=firstplace;j<strlen(str[i]);j++)
printf("%c",str[i][j]);
printf("\n");
}
return 0;
}
created
last reply
- 10
replies
- 849
views
- 2
users
- 2
links