其他分享
首页 > 其他分享> > PAT-1027 Colors in Mars

PAT-1027 Colors in Mars

作者:互联网

1027 Colors in Mars

part 1, 1.2

自己解法

#include <iostream>
using namespace std;

void printColor(int c)
{
    int qu, re;
    qu = c / 13;
    re = c % 13;
    char repColor[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};
    cout << repColor[qu] << repColor[re];
}

int main()
{
    int R, G, B;
    cin >> R >> G >> B;
    cout << "#";
    printColor(R);
    printColor(G);
    printColor(B);
    cout << endl;
    system("pause");
    return 0;
}

大神解法

#include <cstdio>
using namespace std;
int main() {
    char c[14] = {"0123456789ABC"};
    printf("#");
    for(int i = 0; i < 3; i++) {
        int num;
        scanf("%d", &num);
        printf("%c%c", c[num/13], c[num%13]);
    }
    return 0;
}

总结

标签:1027,PAT,cout,int,13,char,Colors,num,printf
来源: https://blog.csdn.net/seven_colors/article/details/122804719