PALIN - The Next Palindrome 对称的数

时间:2023-03-08 15:34:54
PALIN - The Next Palindrome 对称的数

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

Input

The first line contains integer t, the number of test cases. Integers K are given in the next t lines.

Output

For each K, output the smallest palindrome larger than K.

Example

PALIN - The Next Palindrome 对称的数

 #include<iostream>
#include<string>
#define MAX 7
using namespace std; int arr[MAX];
int ptr;
string ss="";
void pushstack(int t)
{
arr[ptr]=t;
ptr++;
} int popstack()
{
ptr--;
return arr[ptr];
} void Palindrome(int m)
{
m=m+;
int i,j; while()
{
i=m;
j=m;
ptr=;
bool tag=false;//标记
while(i>)
{
int k;
k=i%;
pushstack(k);
i=i/;
}
while(j>)
{
int k;
k=j%;
int f=popstack();
if(k!=f)
break;
else if(k==f&&ptr==)
{
tag=true;
char s[MAX];
sprintf(s,"%d\n",m);
ss=ss+s;
}
j=j/;
}
if(tag==true)
break;
m=m+;
} } int main()
{
int i;
cin>>i;
while(i>)
{
int j;
cin>>j;
i--;
Palindrome(j);
}
cout<<ss<<endl;
return ;
}

代码截图:

PALIN - The Next Palindrome 对称的数

2016-12-3114:24:08 By--LeeVanVan