题目描述
高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b]
输入输出格式
输入格式:
分两行输入a,b<=10^500
输出格式:
输出只有一行,代表A+B的值
输入输出样例
输入样例#1:
1
1
var x,y,ans:string; i,j,lena,lenb,lenc:longint; flag:boolean; a,b,c:array[0..10000]of longint; function calc(n:longint):longint; var i,j,k,l:longint; begin for i:=1 to n do begin c[i]:=c[i]+a[i]+b[i]; inc(c[i+1],c[i] div 10); c[i]:=c[i] mod 10; end; if c[n+1]<>0 then exit(n+1); exit(n); end;begin readln(x); readln(y); lena:=length(x); lenb:=length(y); for i:=1 to lena do a[lena-i+1]:=ord(x[i])-ord('0'); for i:=1 to lenb do b[lenb-i+1]:=ord(y[i])-ord('0'); lenc:=calc(max(lena,lenb)); for i:=lenc downto 1 do if (flag=false)and(c[i]=0) then continue else begin write(c[i]); flag:=true; end; if flag=false then writeln(0);end.
输出样例#1:
2