#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include<map>
using namespace std;
int M, N, L, K, a, b, c;
string suma;
bool huiwen(string input1, string input2)
{
if (input1 == input2)
return true;
else
return false;
}
string add_str(string str_a, string str_b)
{
reverse(str_a.begin(), str_a.end());
reverse(str_b.begin(), str_b.end());
if (str_b.size()<str_a.size())
{
str_b.resize(str_a.size());
}
bool flag_1 = false;
string out_str;
for (int i = 0; i < str_a.size(); i++)
{
a=str_a[i] + str_b[i] - '0' - '0'+flag_1;
flag_1 = false;
if (a>9)
{
flag_1 = true;
a -= 10;
}
out_str += to_string(a);
}
if (flag_1==true)
{
out_str += '1';
}
reverse(out_str.begin(), out_str.end());
return out_str;
}
int main()
{
cin >> suma;
int cnt = 0;
for (; cnt < 10; cnt++)
{
string str1(suma);
string s(str1.rbegin(), str1.rend());
if (huiwen(str1, s))
{
cout << suma << " is a palindromic number." << endl;
break;
}
suma=add_str(suma, s);
cout << str1 << " + " << s << " = " << suma << endl;
}
if (cnt == 10)
{
cout << "Not found in 10 iterations." << endl;
}
system("pause");
return 0;
}
网友评论