输入两个非负 10 进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数。
输入格式:
输入在一行中依次给出 3 个整数 A、B 和 D。
输出格式:
输出 A+B 的 D 进制数。
输入样例:
123 456 8
输出样例:
1103
#include <iostream>
#include <stack>
#include <algorithm>
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;
}
218

被折叠的 条评论
为什么被折叠?



