PAT (Basic Level) Practice (中文)
announcement
PAT original site users can https://patest.cn/bind_old_pat_user bound to A title fight Account page. After binding, the site of the original PAT submission will be incorporated into the title fight A website user corresponding topic focus.
1022 D hexadecimal A + B (20 minutes)
Enter two non-negative decimal integers A and B (≤2 30 -1), the output A + B of the D (1 <D≤10) binary number.
Input formats:
A given integer input successively three in a row, B and D.
Output formats:
Output A + D B of the hexadecimal number.
Sample input:
123 456 8
Sample output:
1103
Ideas:
Simulation obtained under each digit hexadecimal m, attention judgment Patent 0;
#include<iostream>
#include<stack>
using namespace std;
int main(void){
long long int a ,b,m;
while( scanf("%lld%lld%lld",&a,&b,&m)!=EOF){
a= a+b;
if( a ==0 ){
printf("0\n");
continue;
}
stack<long long int> s;
if( m !=10 ){
while( a ){
b=a%m;
a=a/m;
s.push(b);
}
while(!s.empty() ){
printf("%lld",s.top());
s.pop();
}
printf("\n");
}
else printf("%lld\n",a);
}
return 0;
}