题目描述:
设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321)
输入:
程序无任何输入数据
输出:
输出题目要求的四位数,如果结果有多组,则每组结果之间以回车隔开
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <stack>
using namespace std;
string toString(int n){
char temp[10];
itoa(n,temp,10);
string s(temp);
return s;
}
bool isFanxushu(int n){
string s = toString(n);
string t = s;
reverse(t.begin(),t.end());
if ( s == t){
return true;
}
return false;
}
int main() {
for (int i = 1000; i <= 9999 ; i++){
if(isFanxushu(i * 9)){
cout<<i<<endl;
}
}
}