题解 | #多多的数字组合#

多多的数字组合

http://www.nowcoder.com/practice/3d6b53e097ea41bda049d111f30db28e

多多的数字组合

#include<stdio.h>

int pow(int num, int n){
    int temp = num;
    if(n == 0){
        return 1;
    }
    for(int i=1;i<n;i++){
        num = num * temp;
    }
    //printf("num = %d\n",num);
    return num;
}
int main(){
    int num = 0, result = 0;
    scanf("%d\n",&num);
    //1~9 累加最大的值为45,如果超过则肯定重复了
    if(num>45){
        printf("%d\n",-1);
        return 0;
    }
    int temp = num;
    for(int i=9; i>=0; i--){
        temp -= i;
        if(temp<=0){
            printf("%d\n",num);
            break;
        }
        //官方编译引入的pow不能用,只能自己写了
        result += i*pow(10,10-i-1);
        if(temp<i){
            result += temp*pow(10,10-i);
            printf("%d\n",result);
            break;
        }

    }
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 17:30
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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