我这里将数字转换为字符串使用的是stringstream字符串流
扩充:将字符串转换为数字可以使用stoi函数,函数头为cstdlib
#include
#include
#include
#include
#include
#include
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
bool ispalindromic(string s){
int len=s.length();
for(int i=0;i
int len=s.length();
string original=s;
if(ispalindromic(original)){
cout<<original<<" is a palindromic number.";
return 0;
}
for(int i=0;i<10;i++){
string temp=original;
string temp1=original;
reverse(temp1.begin(),temp1.end());
original=add(temp,temp1);
cout<<temp<<" + "<<temp1<<" = "<<original<<endl;
if(ispalindromic(original)){
cout<<original<<" is a palindromic number.";
return 0;
}
}
cout<<"Not found in 10 iterations."<<endl;
return 0;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章