1022 D进制的A+B (20 分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805299301433344

输入两个非负 10 进制整数 A 和 B (≤),输出 A+B 的 D (1)进制数。

输入格式:

输入在一行中依次给出 3 个整数 A、B 和 D。

输出格式:

输出 A+B 的 D 进制数。

输入样例:

123 456 8

输出样例:

1103

利用栈将10进制转为其他进制
#include<bits/stdc++.h>
using namespace std;
void reverse(int n,int degree){
    stack<int> s;
    while(n){
        s.push(n%degree);
        n/=degree;
    }
    int sum = 0;
    while(!s.empty()){
        cout<<s.top();
        s.pop();
    }
}
int main(){
int a,b,c;
    cin>>a>>b>>c;
    
    int d = a + b;
    if(d==0)
    cout<<"0"<<endl;
    else
    reverse(d,c);
    

    return 0;
}
原文地址:https://www.cnblogs.com/siro/p/11121531.html