https://www.nowcoder.com/pat/2/problem/270
吐槽:注意最后输出形式是r进制,不是十进制。

#include<cstdio>
#include<cstring>
char str[50];
void change(int num,int x){
    memset(str,0,sizeof(str));
    int  k = 0,sum = 0;
    do{
        sum +=  num % x;
        num /= x;
    }while(num!=0); 
   do{
     int tmp = sum % x;
     if(tmp > 9) str[k++] = tmp + 'A' - 10;
     else str[k++] = tmp + '0';
     sum /= x;
   }while(sum!=0);
   for(int i=k-1;i>=0;i--){
    printf("%c",str[i]);
   }
   printf("\n");
}
int main(){
    int n,r;
    while(scanf("%d%d",&n,&r) != EOF){
        change(n,r); 
    } 
    return 0;
}