[PAT解题报告] Colors in Mars

简单题,把3个数变成13进制,而且每个数要求变成两位13进制数。
对于x,变为13进制,高位“数字”是(x / 13),低位数字是(x % 13),然后直接输出就可以了。感觉比1001那种要处理的A + B还简单。

代码:
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

const char *s = "0123456789ABC";

void print(int x) {
    printf("%c%c",s[x / 13],s[x % 13]);
}
int main() {
int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    putchar('#');
    print(a);
    print(b);
    print(c);
    puts("");
    return 0;
}

原题链接: http://www.patest.cn/contests/pat-a-practise/1027


全部评论
#include <bits/stdc++.h> using namespace std; char ischar(int x) {     if(x>=0&&x<=9) return x+'0';     else return 'A'+(x-10); } int main() {     int r,y,b;     ios::sync_with_stdio(false);     cin>>r>>y>>b;     cout<<'#';     cout<<ischar(r/13)<<ischar(r%13)<<ischar(y/13)<<ischar(y%13)<<ischar(b/13)<<ischar(b%13)<<endl; }
点赞
送花
回复
分享
发布于 2017-10-13 21:15

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务