1027 Colors in Mars (20 分)

由于题目的数据范围为[0, 168],因此给定的整数x在十三进制下一定可以表示为\(x=a*13^1+b*13^0\)(因为\(168<13^2\)),于是只要想办法求出a跟b即可。

对上面的等式两边同时整除13,可以得到\(\lfloor x/13 \rfloor =a\);对上面的等式两边同时对13取模,可以得到\(x%13=b\)。这样就得到了a与b,接下来只需要输出即可。

char get(int x)
{
    if(x<10) return '0'+x;
    else return x-10+'A';
}

int main()
{
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];

    cout<<'#';
    for(int i=0;i<3;i++) cout<<get(a[i]/13)<<get(a[i]%13);
    //system("pause");
    return 0;
}
posted @ 2021-02-12 23:08  Dazzling!  阅读(28)  评论(0编辑  收藏  举报