标签:namespace 字符串 ati com 这一 http include 差值 blog
#include<iostream>
#include<algorithm>
using namespace std;
string rev(string s){
reverse(s.begin(), s.end());
return s;
}
string add(string s1, string s2){
int carry = 0;
string s = s1;
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(){
int n = 10;
string s, sum;
cin >> s;
if(s == rev(s)){
cout << s << " is a palindromic number.";
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.";
return 0;
}
s = sum;
}
cout << "Not found in 10 iterations.";
return 0;
}
A1136 A Delayed Palindrome (20分)
标签:namespace 字符串 ati com 这一 http include 差值 blog
原文地址:https://www.cnblogs.com/tsruixi/p/13149493.html