提交时间:2024-04-06 08:40:10

运行 ID: 141586

#include <iostream> #include <stack> using namespace std; stack <char> a; string h = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int n, d; cin >> n >> d; if(n == 0) { cout << 0 << endl; return 0; } while(n) { int t = n % d; char pushnum; if(t > 9) pushnum = h[t - 10]; else pushnum = char(t + '0'); a.push(pushnum); n /= d; } while(!a.empty()) { cout << a.top(); a.pop(); } cout << endl; return 0; }