Palindrome Number conjecture problem description A positive integer, if read from left to right (called the positive ordinal) and read from right to left (called the reverse number) is the same, such number is called Palindrome number. Either take a positive integer, if it is not a palindrome number, the number and his reverse number is added, if it is not a palindrome number, repeat the above steps until the palindrome number is obtained. For example: 68 becomes 154 (68+86), then 605 (154+451), finally becomes 1111 (605+506), and 1111 is a palindrome number. Then a mathematician proposed a conjecture: no matter what the starting is a positive integer, after the finite number of positive and reverse sequence of the addition of the steps, you will get a palindrome number. So far, it is not known whether this conjecture is right or wrong. Now please compile the program to verify it. Input is a positive integer per line.
Special note: The input data guarantees that the intermediate result is less than 2^31. Output corresponds to each input, outputs two lines, one line is the number of transformations, and one row is the process of transformation. Sample Input2722837649 Sample Output327228--->109500--->115401--->219912237649--->132322--->355553
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intb[ -];6 intCount=0;7 intJudgeintnum)8 {9 intI=0, t=0;TenCount=0; Onememset (b,0,sizeof(b)); A while(num!=0) - { -b[count++]=num%Ten; theNum/=Ten; - } - for(i=0, t=count-1;! (i==t+1|| I==T); i++,t--) - { + if(b[i]!=B[t]) - return 0;//not a palindrome number . + } A return 1;//It's a palindrome number . at } - int Get() - { - intkk=0; - intI=0; - for(i=0; i<count;i++) inkk=kk*Ten+B[i]; - returnKK; to } + intMain () - { the intnum; * inta[ +]; $ while(cin>>num)Panax Notoginseng { - intI=0; theMemset (A,0,sizeof(a)); + while(!judge (num)) A { thea[i++]=num; +num=Get()+num; - } $cout<<i<<Endl; $ if(i==0) -cout<<'1'<<endl<<num; - Else the { - for(intj=0; j<i;j++)Wuyicout<<a[j]<<"--->"; thecout<<num<<Endl; - } Wu } -}
Palindrome number conjecture (hd1282)