#include <cmath>
#include <iostream>
using namespace std;

int func(int x);

int main() {
    int a=1000;
    while (a<=1111) { // 注意 while 处理多个 case
        int b = func(a);
        if(a*9==b){
            cout<<a<<endl;
        }
        a++;
    }

    // int b = func(a);
    // cout<<b;
}

int func(int x){
    int res=0;
    while (x>0) {
        res*=10;
        res += x%10;
        x/=10;
    }
    return res;
}
// 64 位输出请用 printf("%lld")

刷题记录01

知识点:对整数的取反;

注意点:先res*=10,再res += x%10,顺序不能乱; 因为res一开始等于0,res*=10放在第一行,相当于整个遍历过程,会少执行一次res*=10;乘以10的次数刚刚好;