#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char my2char(int num)
{
if(num<10)
return num+'0';
else
return num-10+'a';
}
int my2int(char ch)
{
if(ch>='0' && ch<='9')
return ch-'0';
else
return ch-'a'+10;
}
string add(string s1,string s2)
{
string s;
if(s1.size()>s2.size())
swap(s1,s2);
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
int tmp=0;
for(int i=0;i<s1.size();i++)
{
int num=my2int(s1[i])+my2int(s2[i])+tmp;
tmp=num/20;
num=num%20;
s+=my2char(num);
}
for(int i=s1.size();i<s2.size();i++)
{
if(tmp!=0)
{
int num=my2int(s2[i])+tmp;
tmp=num/20;
num=num%20;
s+=my2char(num);
}
else
s+=s2[i];
}
if(tmp!=0)
s+=my2char(tmp);
reverse(s.begin(),s.end());
return s;
}
int main()
{
string s1,s2;
while(cin>>s1>>s2)
{
cout<<add(s1,s2)<<endl;
}
return 0;
}
Zoj1205
最新推荐文章于 2018-02-11 20:20:35 发布