此题注意c中无reverse函数,用模的方法进行reverse操作。计算反转数时忘注意回文数,导致了最开始想减小计算域,结果从1开始也不会超时。C'est tout.
Description
Give you a number M (9999<=M<=9999999).
Output the number of total numbers such that the sum of this number and its reverse is M.
Input
There are several lines. And each line contains a positive number M (9999<=M<=9999999).
Output
Output the number of total numbers such that the sum of this number and its reverse is M.
Output 0 if there is no such numbers.
For example,
Input
1333
2444
Output
6
0
Because 419, 518, 617, 716, 815, 914 are total numbers such that the sum of this number and its reverse is 1333. (419+914=1333)
Sample Input
1333
2444
Sample Output
6
0
HINT
#include <stdio.h>
#include <stdlib.h>
int reverse(int x)
{
int r = 0;
while(x)
{
r=r*10+x%10;
x/=10;
}
return r;
}
int main()
{ int n,j,i,num;
while (scanf("%d",&n)!=EOF){
num=0;
for(i=1;i<=n;i++){
j=reverse(i);
if(n==j+i)
num+=1;
}
printf("%d\n",num);}
return 0;
}