PAT B Zhenti 1012.D hex A + B
Title Description
Enter two non-negative decimal integers A and B (<= 230-1), the output A + D B (1 <D <= 10) Number of decimal.
Input Format
A given integer input successively three in a row, B and D.
Output Format
Output A + D B of the hexadecimal number.
SAMPLE INPUT
123 456 8
Sample Output
1103
Topic ideas
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll a,b;
int d;
scanf("%lld%lld%d",&a,&b,&d);
a += b;
if(a==0)
{
printf("0");
}
else
{
stack<int> s;
while(a/d)
{
s.push(a%d);
a/=d;
}
s.push(a);
while(!s.empty())
{
printf("%d",s.top());
s.pop();
}
}
return 0;
}