反序数(翻转string、int string互转)

题目描述:

设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;
        }
    }


}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值