杭电 -- 1197

#include<stdio.h>
#include<string.h> 

int trans(int n,int type){
    int sum = 0;
    int index = 0;
    if(type==16){
        while(n != 0){
            sum += n%type;
            n = n/type;            
        }
    }else if(type==12){
        while(n != 0){
            sum += n%type;
            n = n/type;         
        }
    }
    return sum;
}

void judge(int res[],int n){
    int flag = 1;
    for(int i=1;i<3;i++){
        if(res[i]!=res[i-1]){
            flag = 0;
            break;
        }
    }
    if(flag){
        printf("%d\n",n);
    }else{
        //do null
    }
}

int sum(int n){
    int res = 0;
    res += n%10+n/10%10+n/10/10%10+n/1000;
    return res;
}

int main(){
    int res[3];
    int k;
    for(int i=2992;i<=9999;i++){
        //reset
        k = 0;
        //10
        res[k++] = sum(i);
        //12
        res[k++] = trans(i,12);
        //16
        res[k++] = trans(i,16);
        //judge
        judge(res,i);
    }
    return 0;
}

Accepted! 但是字符与数字之间的转。。。。我是真的菜!

转载于:https://www.cnblogs.com/kyrie211/p/11088814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值