#include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<algorithm> #include<map> #include<vector> #include<queue> #include<string> /* /*注意1:字符串存数字时低位存数字的高位 注意2:"1"+s是在字符串s首加了1 */ using namespace std; string rev(string s){ reverse(s.begin(),s.end()); return s; } string add(string s1,string s2){//大整数加法 string s=s1; int carry=0; for(int i=s1.size()-1;i>=0;i--){ s[i]=(s1[i]-'0'+s2[i]-'0'+carry)%10+'0'; carry=(s1[i]-'0'+s2[i]-'0'+carry)/10; } if(carry>0) s="1"+s; return s; } int main(){ string s,sum; int n=10; cin>>s; if(s==rev(s)){ cout<<s<<" is a palindromic number.\n"; return 0; } while(n--){ sum=add(s,rev(s)); cout<<s<<" + "<<rev(s)<<" = "<<sum<<endl; if(sum==rev(sum)){ cout<<sum<<" is a palindromic number.\n"; return 0; } s=sum; } cout <<"Not found in 10 iterations.\n"; //system("pause"); return 0; }