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 1189. Pairs of Integers

qwt Why I got wang answer? // Problem 1189. Pairs of Integers 25 Mar 2002 18:22
const
  u:array[0..9] of longint=
(1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000);
  maxn=100;
var
  s:string;e:integer;l,tot,t,x,y,n,i,m,j,k:longint;
  list:array[1..maxn] of longint;
begin
  readln(s);
  val(s,n,e);
  l:=length(s)-1;
  k:=0;
  tot:=0;
  repeat
    x:=0;
    y:=0;
    m:=n;
    for x:=n div (11*u[k]) downto n div (11*u[k])-1 do if x>=0 then
begin
      dec(m,x*11*u[k]);
      for t:=m div u[k] downto m div u[k]-1 do if (t<10)and((x>0)and
(t>=0))or((x=0)and(t>0)) then begin
        dec(m,t*u[k]);
        if (k>0)and(m>=0)and(m mod 2=0)and(m>=0)and(m div 2<u[k])
then begin
          inc(tot);
          list[tot]:=x*10*u[k]+t*u[k]+m div 2;
          for i:=1 to tot-1 do if list[tot]=list[i] then
            dec(tot);
        end else
        if (k=0)and(m=0) then begin
          inc(tot);
          list[tot]:=x*10*u[k]+t*u[k];
          for i:=1 to tot-1 do if list[tot]=list[i] then
            dec(tot);
        end;
        inc(m,t*u[k]);
      end;
      inc(m,x*11*u[k]);
    end;
    inc(k);
  until k>l;
  writeln(tot);
  for i:=1 to tot do begin
    str(list[i],s);
    l:=length(s);
    str(n-list[i],s);
    while length(s)<l-1 do s:='0'+s;
    writeln(list[i],' + ',s,' = ',n);
  end;
end.