Cod sursa(job #142990)

Utilizator antoanelaAntoanela Siminiuc antoanela Data 25 februarie 2008 19:19:42
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.63 kb
program cifra;
var f,g:text;
    a,v:array[1..1000]of longint;
    t,y,n,ok,p,c,r,k,i,s:longint;
    x:char;
begin
assign(f,'cifra.in');
assign(g,'cifra.out');
reset(f);
rewrite(g);
readln(f,t);
for y:=1 to t do
  begin
    n:=0;
    while not eoln(f) do
      begin
        inc(n);
        read(f,x);
        v[n]:=ord(x)-ord('0');
      end;
    readln(f);
    ok:=0;
    if (n=1)then ok:=1 else
    if (n=2)and(v[1]<2)then ok:=1 else
    if (n=2)and(v[1]=2)and(v[2]=0)then ok:=1;
    if (ok=0)then
      begin
        if (v[1]*10+v[2]>=20)then
          begin
            p:=v[1]*10+v[2];
            c:=2;
          end else
          begin
            p:=v[1]*100+(v[2]*10)+v[3];
            c:=3;
          end;
        while (c<=n)do
          begin
            k:=p div 20;
            r:=p mod 20;
            inc(c);
            p:=r*10+v[c];
          end;
        n:=r;
      end;
    if (v[n]=1)then s:=1 else
    if (v[n]=2)then s:=5 else
    if (v[n]=3)then s:=2 else
    if (v[n]=4)then s:=8 else
    if (v[n]=5)then s:=3 else
    if (v[n]=6)then s:=9 else
    if (v[n]=7)then s:=2 else
    if (v[n]=8)then s:=8 else
    if (v[n]=9)then s:=7 else
    if (v[n]=10)then s:=7 else
    if (v[n]=11)then s:=8 else
    if (v[n]=12)then s:=4 else
    if (v[n]=13)then s:=7 else
    if (v[n]=14)then s:=3 else
    if (v[n]=15)then s:=8 else
    if (v[n]=16)then s:=4 else
    if (v[n]=17)then s:=1 else
    if (v[n]=18)then s:=5 else
    if (v[n]=19)then s:=4 else
    if (v[n]=20)then s:=4;
    if (ok=0)then writeln(g,(4*k+s)mod 10) else writeln(g,s);
  end;

close(f);
close(g);
end.