牛客编程题(C语言):HJ5 进制转换

https://www.nowcoder.com/exam/oj/ta?tpId=37

https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

提交代码

#include <stdio.h>
int main() {
    char ch[100];
    gets(ch);
    int res=0,num;
    int i=0;
    while(ch[i]!='\0'){
        if(i>1){
            if(ch[i]>='0'&&ch[i]<='9'){
                num = ch[i]-'0';
            }else if(ch[i]>='A'&&ch[i]<='G'){
                num = ch[i]-'A'+10;
            }
            res *= 16;
            res += num;
        }
        i++;
    }
    printf("%d\n",res);
    return 0;
}

执行结果

posted @ 2022-05-15 17:29  孤舟浮岸  阅读(143)  评论(0编辑  收藏  举报