题目

题意:给定数在十次加法运算以内是否能得到回文数

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool pal(string s) {
	int l=0,r=s.size()-1;
	while(l<r) {
		if(s[r]==s[l]) {
			r--;
			l++;
		} else break;
	}
	return l>=r;
}
int main() {

	string ans;
	int t=10;
	cin>>ans;
	if(pal(ans))
		cout<<ans<<" is a palindromic number.\n";
	else {
		while(t--) {
			string temp=ans;
			reverse(ans.begin(),ans.end());
			cout<<temp<<" + "<<ans<<" = ";
			string f="";
			int it=0;
			for(int i=ans.size()-1; i>=0; --i) {
				f=to_string((ans[i]+temp[i]+it-'0'-'0')%10)+f;
				it=(ans[i]+temp[i]+it-'0'-'0')/10;
			}
			if(it)
				f="1"+f;
			cout<<f<<endl;
			if(pal(f)) {
				cout<<f<<" is a palindromic number.\n";
				t=10;
				break;
			} else ans=f;
		}
	}
	if(t<0)
		cout<<"Not found in 10 iterations.\n";
	return 0;
}