蒟蒻的我...

#include<bits/stdc++.h>
using namespace std;

int charToNumber(char c)
{
    switch(c)
    {
        case '0':return 0;
        case '1':return 1;
        case '2':return 2;
        case '3':return 3;
        case '4':return 4;
        case '5':return 5;
        case '6':return 6;
        case '7':return 7;
        case '8':return 8;
        case '9':return 9;
        case 'A':return 10;
        case 'B':return 11;
        case 'C':return 12;
        case 'D':return 13;
        case 'E':return 14;
        case 'F':return 15;
        case 'a':return 10;
        case 'b':return 11;
        case 'c':return 12;
        case 'd':return 13;
        case 'e':return 14;
        case 'f':return 15;
    }
    return 0;
}
char  numberToChar(int n)
{
     switch(n)
    {
        case 0:return '0';
        case 1:return '1';
        case 2:return '2';
        case 3:return '3';
        case 4:return '4';
        case 5:return '5';
        case 6:return '6';
        case 7:return '7';
        case 8:return '8';
        case 9:return '9';
        case 10:return 'A';
        case 11:return 'B';
        case 12:return 'C';
        case 13:return 'D';
        case 14:return 'E';
        case 15:return 'F';
     }
    return '0';
}
//进制转换
string converse(int n,string str,int m)
{
    int carry,k;//高位向低位的进位
    string res="";
    for(int i=0;i<str.size();)
    {
        carry=0;
        for(int j=i;j<str.size();j++)
        {
            k = (charToNumber(str[j])+carry*n)%m;
            str[j] = numberToChar((charToNumber(str[j])+carry*n)/m);
            carry=k;
        }
        res+=numberToChar(carry);
        while(str[i] == '0') i++;
    }
    reverse(res.begin(),res.end());
    return res;
}
int main()
{
    int n,m;
    string str;
    while(cin>>n>>str>>m)
    {
        cout<<converse(n,str,m)<<endl;
    }
}