题解 | 反序相等

反序相等

https://www.nowcoder.com/practice/092e7068881549bd8985c379208ef3c2

#include <iostream>
using namespace std;

int reverse(int n) {
    int t = n;
    int count = 0;
    while (t) {
        count++;
        t /= 10;
    }
    t = n;
    int a[count];
    for (int i = 0; i < count; i++) {
        a[i] = t % 10;
        t /= 10;
    }
    t = 0;
    for (int i = 0; i < count; i++) {
        t += a[i];
        t *= 10;
    }
    return t / 10;
}

int main() {
    bool flag = false;
    for (int i = 1000; i < 10000; i++) {
        if (i * 9 == reverse(i))     {
            cout << i << endl;
            flag = true;
        }
    }
    if (!flag)   cout << "无" << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
Aaso:挺好的,早挂早超生
点赞 评论 收藏
分享
神哥不得了:神哥来啦~1.建议不要包装,很容易问穿2.没日常也能找到暑期3.简历模板换一下,字体和版式看着好难受,而且最好压缩到一页,技术的倒数第2和3重复啦,项目建议换两个高质量的上去,如果时间够的话,八股就把高频top50的题目多巩固几遍,吃透,注意不要找假高频,这样绝对能找到暑期
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务