?? a+b.cpp
字號:
#include <stdio.h>
#include<string.h>
char a[501],b[501],c[502],*x,*y;
int p,t,k,s,max,min;
inline int input(char *q)
{
if(scanf("%s", q) != 1)
return 0;
return strlen(q);
}
inline void output()
{
int i,j;
k--;s--;
if(k>=s)
{ max=k;x=a; /* (k=input(a))&&(s=input(b))*/
min=s;y=b;
}
else
{
max=s;x=b;
min=k;y=a;
}
for(i=max,j=min,p=0;j>=0;i--,j--)
{
t=(x[i]-'0')+(y[j]-'0')+p;
c[i+1]=t%10+'0';
p=t/10;
}
if(!p)
{ for(j=1;j<=i+1;j++)
{
c[j]=x[j-1];
}
c[0]='0';
}
else{ for(j=i;j>=0;j--)
{
t=p+(x[j]-'0');
c[j+1]=t%10+'0';
p=t/10;
}
if(!p) c[0]='0';
else c[0]=p+'0';
}
if(c[0]=='0')
for(j=1;j<=max+1;j++)
putchar(c[j]);
else
for(j=0;j<=max+1;j++)
putchar(c[j]); /* printf("%c",c[i])*/
printf("\n");
}
void deal()
{
while((k=input(a))&&(s=input(b)))
{
output();
}
}
int main()
{
deal();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -