Pat_1022(乙级) | StriveZs的博客

Pat_1022(乙级)

1022 D进制的A+B (20 分)原文地址

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

输入格式:

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

输出格式:

输出 A+B 的 D 进制数。

输入样例:

123 456 8

输出样例:

1103

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<stack>

using namespace std;


int main(){
stack<int> qwe;
long long A,B,C,D;
cin>>A>>B>>D;
C = A + B;
if(C==0){
cout<<"0"<<endl;
}
else{
while(C!=0){
int t = C % D;
qwe.push(t);
C = C / D;
}
while(!qwe.empty()){
cout<<qwe.top();
qwe.pop();
}
}
return 0;
}
StriveZs wechat
Hobby lead  creation, technology change world.
  • Post author: StriveZs
  • Post link: 1663.html
  • Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.