题解 | #变种水仙花#

变种水仙花

https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71

#include <stdio.h>


#define MAX 99999

int LilyNumber(const int n) {
    int sum = 0;
    int m = n;
    int count = 0;
    while (m) {
        m /= 10;
        count++;
    }
    int i = 0;
    for (i = 1; i < count; i++) {
        int a = n;
        int b = n;
        int c = count - i;
        int d = i;
        while (c--) {
            a /= 10;
        }
        while (d--) {
            int e = count - i;
            int d = 1;
            while (e--) {
                d *= 10;
            }
            b %= d;
        }
        sum += a * b;
    }
    if (sum == n) {
        return n;
    } else {
        return 0;
    }
}

int main() {
    int i = 0;
    for (i = 10000; i <= MAX; i++) {
        int ret = LilyNumber(i);
        if (ret) {
            printf("%d ", ret);
        }
    }

    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务