https://pintia.cn/problem-sets/994805260223102976/problems/994805261754023936
首先确定给定的整数是不是回文串 如果是就不需要输出A+B=C了
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int check(string s){
string tmp = s;
reverse(tmp.begin(), tmp.end());
if(s == tmp) return 1;
else return 0;
}
int main(){
string s, rs;
char abc[10] = {'0','1','2','3','4','5','6','7','8','9'};
cin >> s;
int cnt = 0;
while(1){
if(check(s)){
cout << s << " is a palindromic number.";
break;
}
cnt++;
string result_s = "";
if(cnt > 10){
cout << "Not found in 10 iterations.";
break;
}
rs = s; reverse(rs.begin(), rs.end());
int carry = 0;
for(int i = 0; i < s.size(); i++){
result_s += abc[(s[i]-'0'+rs[i]-'0'+carry)%10];
carry = (s[i]-'0'+rs[i]-'0'+carry)/10;
}
if(carry)
result_s += abc[carry];
reverse(result_s.begin(), result_s.end());
cout << s << " + " << rs << " = " << result_s << endl;
s = result_s;
}
return 0;
}