ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1000. A+B Problem

Solution for (0<A+B<10^2^64-1)
Posted by VladimirZagorodskih 20 Jan 2010 10:30
program Project1;
{$APPTYPE CONSOLE}
var
 sym : char;
 a, b : AnsiString;
 la, lb, i : qword;
 l, m, n : byte;
 c : array of byte;
begin
  read(sym);
  repeat
  a:=a+sym;
  read(sym);
  until (sym=' ');
  readln(b);
  la:=length(a);
  lb:=length(b);
  if la>lb then setlength(c, la) else setlength(c, lb);
  i:=0;
  n:=0;
  repeat
    i:=i+1;
    if la>0 then l:=ord(a[la])-48 else l:=0;
    if lb>0 then m:=ord(b[lb])-48 else m:=0;
    c[i]:=l+m+n;
    n:=c[i] div 10;
    c[i]:=c[i] mod 10;
    if la>0 then la:=la-1;
    if lb>0 then lb:=lb-1;
  until (la<=0) and (lb<=0) and (n=0);
  while (i>0) do begin
  write(c[i]);
  i:=i-1;
  end;
end.

=)
      (=
Re: Solution for (0<A+B<10^2^64-1)
Posted by tiancaihb 20 Jan 2010 19:11
just high precision, but a bit slow
Re: Solution for (0<A+B<10^2^64-1)
Posted by Anisimov Dmitry (Novosibirsk STU) 28 Jan 2010 15:57
Or just use unsigned long long in C...
Re: Solution for (0<A+B<10^2^64-1)
Posted by VladimirZagorodskih 19 Feb 2010 20:04
I know that this problem can be solved by this:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  a, b : longint;
begin
  read(a,b);
  write(a+b);
end.

I did it just for fun))))