任意进制转化 c(c++)

来源:互联网 发布:windows 删除文件夹 编辑:程序博客网 时间:2024/05/16 09:38
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<queue> #include<map>#include<queue>#include<stack>typedef long long LL;using namespace std;//map<char ,int> mm;//queue<char> Q;char a[100];int main(){    int b;    stack<LL> Q;    while (cin >> a >> b)    {        LL ans = 0;        for (int i=0;a[i];i++)        {            ans *= 26;            ans += (a[i] - 'a');        }//这只是一个先转化为10进制的方法,可以随意替代        //cout << ans << endl;        while (ans)        {            Q.push(ans%b);            ans /= b;        }        int f = 0;        while (!Q.empty())        {            f = 1;            int s = Q.top();            Q.pop();            cout << s;        }        if (!f)        {            puts("0");        }        else        {            puts("");        }    }    return 0;}
原创粉丝点击