[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/************************************************************************************************************************************************************
****
**** begin: 2012 10 12
**** 回文數
**** 找出大於一個數的最小回文數
**** end : 2012 10 12
****
************************************************************************************************************************************************************/
void main(){
char data[10] = {0}, res[10] = {0}, state[10] = {0}, len = 0, pos, bit = 0;
scanf("%s",data);
len = strlen(data);
if(len % 2 == 0){//偶
pos = len/2 - 1;
}
else{
pos = len/2;
}
while(pos - bit >= 0){
if(len % 2 == 1){
if(data[pos - bit] >= data[pos + bit]){
res[pos - bit] = data[pos - bit];
res[pos + bit] = data[pos - bit];
}
else{
data[pos - bit + 1]++;
memset(&data[pos - bit + 2], '0', len - (pos - bit+1));
bit = 0;
continue;
}
bit ++;
}
else{
if(data[pos - bit] >= data[pos + 1 + bit]){
res[pos - bit] = data[pos - bit];
res[pos + 1 + bit] = data[pos - bit];
}
else{
data[pos - bit ]++;
memset(&data[pos - bit + 1], '0', len - (pos - bit+1) + 1);
bit = 0;
continue;
}
bit ++;
}
}
printf("回文數為%s", res);
}