1820:【00NOIP提高组】进制转换

 

 

#include<bits/stdc++.h>//十分简单(滑稽)的一道模拟题 
using namespace std;
char num[10]={'A','B','C','D','E','F','G','H','I','J'};
int n,a,ans[300],tot;
int main()
{
    int i;
    while(~scanf("%d",&n))
    {
        scanf("%d",&a);tot=0;
        //memset(ans,0,sizeof(ans));
        while(n)
        {
            ans[++tot]=n%a;
            n/=a;
            if(ans[tot]<0) ans[tot]-=a,n++;//进位和借位处理注意这里是负数基数和正数正好相反 
        }
        for(i=tot;i>=1;i--) 
        {
            if(ans[i]<10) printf("%d",ans[i]);
            else printf("%c",num[ans[i]-10]);
        }
        putchar('
');
    }
    return 0;
}

打算在比赛前能刷多少真题就尽量做多少,考试别爆零QAQ

 
原文地址:https://www.cnblogs.com/smartljy/p/11715918.html