project_Euler problem 4 :寻找两个三位数乘积结果中,最大的回文数
?
“回文数从两边读值是一样的。两个两位数乘积的最大回文数是9009=91*99,求两个三位数乘积的最大回文数?”
?
#include <iostream>
#include <sstream>
#include <string>
#include ? <algorithm>
using namespace std;
//转成字符串
string num2str(long i){
?
stringstream ss;
ss <<std::fixed<< i;
return ss.str();
}
//判断回文
bool isPalindromic(string str){
string tmp = str;
reverse(str.begin(),str.end());
if(tmp == str){
return true;
}
return false;
}
?
int main(int argc, char** argv) {
?
? ? for(int i=999; i>=100; i--){
? ? for(int j=999; j>=100; j--){
? ? long tmp = i*j;
? ? if(isPalindromic(num2str(tmp))){
? ? if(i>j){
? ? if(tmp > max)max=tmp;
? ? }
? ? }
? ? }
? ? }
cout << max;
return 0;
}
?