添加链接描述
高精度加法判断回文数
#include<bits/stdc++.h>
using namespace std;
bool check(string s){
string p=s;
reverse(p.begin(),p.end());
return p==s;
}
string add_(string a,string b){
string c;
int p=0;
for(int i=0;i<max((int)a.size(),(int)b.size());i++){
if(i<a.size())p+=a[i]-'0';
if(i<b.size())p+=b[i]-'0';
c+=p%10+'0';
p/=10;
}
if(p)c+=p+'0';
reverse(c.begin(),c.end());
return c;
}
int main(){
string s;
cin>>s;
int cnt=0;
while(!check(s)){
if(cnt==10)break;
cnt++;
string p=s;
reverse(p.begin(),p.end());
string res=add_(p,s);
cout<<s<<" + "<<p<<" = "<<res<<endl;
s=res;
}
if(cnt==10)puts("Not found in 10 iterations.");
else cout<<s<<" is a palindromic number."<<endl;
return 0;
}