1.题目介绍
2.考察点,难度
高精度题,string字符串处理,难度易
3.解题代码
#include <bits/stdc++.h>
using namespace std;
int main(){
string s,k,sum;
int cnt=0;
cin>>s;
k=s;
reverse(k.begin(),k.end());
while(k!=s && cnt<10){
cout<<s<<" + "<<k<<" = ";
int flag=0;
sum="";
for(int i=0;i<s.length();i++){
sum = sum+to_string((flag + s[i]-'0' + k[i]-'0')%10);
flag=flag + s[i]-'0' + k[i]-'0')/10;
}
if(flag) sum=sum+to_string(flag);
reverse(sum.begin(),sum.end());
cout<<sum<<endl;
cnt++;
s=k=sum;
reverse(k.begin(),k.end());
}
if(cnt>=10 && k!=s) cout<<"Not found in 10 iterations."<<endl;
else cout<<s<<" is a palindromic number."<<endl;
}
4.原题地址
https://pintia.cn/problem-sets/994805342720868352/problems/994805345732378624