PAT初级1022D进制的A+B
题目:
思路:
模拟进制转换,取余验商后倒排余数即可
代码:
# include<iostream>
# include<cstring>
using namespace std;
int main()
{
long A,B;
int D,mod;
cin>>A>>B>>D;
long re;
string result="";
re = A + B;
while(re!=0)
{
mod = re%D;
re = re/D;
result = std::to_string(mod) + result;
}
if((A+B)==0)
{
cout<<0<<endl;
}
else
{
cout<<result<<endl;
}
return 0;
}