http://acm.scu.edu.cn/soj/problem.action?id=1116
太水了,没啥可说的。直接上代码吧。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int num[10];
int mun[10];
char str[5];
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
memset(num,0,sizeof(num));
memset(mun,0,sizeof(mun));
scanf("%s",&str);
int len = strlen(str);
for(int i = 0; i < len; i++)
num[i+1] = str[i] - '0';
int flag = 0;
int time = 0;
while(!flag && time < 9)
{
for(int i = 1; i <= len; i++)
mun[len - i + 1] = num[i];
for(int i = 1; i <= len; i++)
{
//printf("%d %d\n",num[i],mun[i]);
int a = num[i];
num[i] = (a + mun[i])%10;
num[i+1] += (a + mun[i])/10;
if(i == len && num[i+1]!= 0)
{
len++;
}
//printf("%d\n",num[i]);
}
time++;
for(int i = 1; i <= len/2; i++)
{
if(num[i] != num[len-i+1])
break;
if(i == len/2) flag =1;
}
}
if(time == 9) printf("0\n");
else printf("%d\n",time);
}
return 0;
}