#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s, rs, sum;
int cnt = 0, flag = 1, yu=0, jin=0;
cin >> s;
while(flag){
rs = s; sum = ""; yu = 0; jin = 0;
reverse(s.begin(), s.end());
if(s == rs){
printf("%s is a palindromic number.", rs.c_str());
break;
}
for(int i = s.length()-1; i >= 0; i--){
yu = (s[i] + rs[i] - '0' - '0'+ jin) % 10;
jin = (s[i] + rs[i] - '0' - '0'+ jin) / 10;
sum.insert(0,to_string(yu));
if(i == 0 && jin > 0) sum.insert(0,to_string(jin));
}
printf("%s + %s = %s\n", rs.c_str(), s.c_str(), sum.c_str());
s = sum;
if(++cnt == 10) {
cout << "Not found in 10 iterations.";
flag = 0;
}
}
return 0;
}
C语言程序设计-1079 延迟的回文数
最新推荐文章于 2023-01-15 18:31:44 发布