题解 | #小红的好数#

小红的好数

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

#include <stdio.h>
#include <stdbool.h>
bool different(int c1, int c2, int c3, int c4, int c5) {
    if(c1 != c2 && c1 != c3 && c1 != c4 && c1 != c5) {
        if(c2 != c3 && c2 != c4 && c2 != c5) {
            if(c3 != c4 && c3 != c5) {
                if(c4 != c5) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int k;
    if (scanf("%d", &k) != EOF) {
        int cur = 98765;
        while(k > 1) {
            cur--;
            int c1 = cur / 10000 % 10;
            int c2 = cur / 1000 % 10;
            int c3 = cur / 100 % 10;
            int c4 = cur / 10 % 10;
            int c5 = cur % 10;
            if(different(c1,c2,c3,c4,c5)) {
                k--;
            }
        }
        if(cur < 10000) {
            printf("0");
        }
        printf("%d\n", cur);
    } else {
        printf("没有输入\n");
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-09 16:39
已编辑
英俊的靓仔offer...:我感觉吧第二个寻迹小车的项目有点配不上你的学历了,写上去扣分了都可能对你来说,好歹是211硕士嘛,写在我这种二本混子的简历上还说得过去,个人观点哦,能再有个好点的项目应该会好很多,或者干脆不写第二个换个啥实习经历?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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