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

xiaoxiao2021-02-28  105

#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; }
转载请注明原文地址: https://www.6miu.com/read-20608.html

最新回复(0)