📄 1205.cpp
字号:
#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[101],b[101],c[101];
int *store;
int m,n,x,y;
while(cin>>a>>b)
{
int i,j,k;
x=strlen(a);
y=strlen(b);
m=x<y?x:y;
n=x>y?x:y;
store=new int[m+1];
memset(store,0,m+1);
for(i=strlen(a)-1,j=strlen(b)-1,k=0;k<m;i--,j--,k++)
{
int p,q;
if(a[i]>57)
p=a[i]-87;
else
p=a[i]-48;
if(b[j]>57)
q=b[j]-87;
else
q=b[j]-48;
if(store[k]==1)
{
store[k]=(p+q+1)%20;
if((p+q+1)>=20)
store[k+1]=1;
if(i==0&&j==0&&(p+q)>=19)//因为前面加1
cout<<'1';
}
else
{
store[k]=(p+q)%20;
if(p+q>=20)
store[k+1]=1;
if(i==0&&j==0&&(p+q)>=20)
cout<<'1';
}
}
int l,d;
for(l=n-1,d=0;l>=n-m;l--,d++)
{
if(store[d]>9)
c[l]=store[d]+87;
else
c[l]=store[d]+48;
}
if(x<y)
strcpy(a,b);
if(store[m]==1)
{
int t=n-m-1;
a[n-m-1]++;
while(a[t]>'f')//要判断加后会不会又要进位
{
a[t]='0';
t--;
if(t<0)
cout<<'1';
if(t<0)
break;
a[t]++;
}
}
for(i=0;i<=n-m-1;i++)
cout<<a[i];
for(i=n-m;i<=n-1;i++)
{
cout<<c[i];
}
cout<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -