PAT A1027 Colors in Mars (20)

AC代码

#include <cstdio>
const int max_n = 1000;
int ans[max_n];
char result[max_n];
char radix[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};
int time = 0;
void change(int a) {
    int num = 0;
    if(a <= 13) { //根据位数来确定是否需要输出多余的0
        result[time++] = '0';
        result[time++] = radix[a];
    } else {
        do {
            ans[num++] = a % 13;
            a /= 13;
        } while(a != 0);
        for(int i = num - 1; i >=0; i--) {
            result[time++] = radix[ans[i]];
        }
    }
}

int main() {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif // ONLINE_JUDGE}
    int a[3] = {0};
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    for(int i = 0; i < 3; i++) {
        change(a[i]);
    }
    printf("#");
    for(int i = 0; i < time; i++) {
        printf("%c", result[i]);
    }
    return 0;
}
posted @ 2019-08-05 15:34  哨音  阅读(85)  评论(0编辑  收藏  举报