Cod sursa(job #47435)

Utilizator taloibogdanTaloi Bogdan Cristian taloibogdan Data 3 aprilie 2007 18:12:57
Problema Cifra Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.23 kb
Program cifra;
Var f,ff:text;
    v:integer;
    s,j,m,n,i:longint;
    h,st:string;
    a:array[0..99] of 0..9;
Begin
  s:=0;
  a[0]:=0;
  for j:=1 to 99 do
     begin
      if (j mod 10=0) or (j mod 10=1) or (j mod 10=5) or (j mod 10=6) then s:=(s+j mod 10) mod 10;
        if j mod 10=2 then
          case j mod 4 of
           2:s:=(s+4) mod 10;
           0:s:=(s+6) mod 10;
          end;
        if j mod 10=3 then
          case j mod 4 of
           3:s:=(s+7) mod 10;
           1:s:=(s+3) mod 10;
          end;
        if j mod 10=4 then s:=(s+6) mod 10;
        if j mod 10=7 then
          case j mod 4 of
           3:s:=(s+3) mod 10;
           1:s:=(s+7) mod 10;
          end;
        if j mod 10=8 then
          case j mod 4 of
           2:s:=(s+4) mod 10;
           0:s:=(s+6) mod 10;
          end;
        if j mod 10=9 then s:=(s+9) mod 10;
        a[j]:=s;
       end;
  assign(ff,'cifra.in');
  reset(ff);
  readln(ff,m);
  assign(f,'cifra.out');
  rewrite(f);
  for i:=1 to m do
     begin
      readln(ff,st);
      h:='';
      if length(st)<>1 then h:=st[length(st)-1];
      h:=h+st[length(st)];
      val(h,n,v);
      Writeln(f,a[n]);
     end;
  close(f);
  close(ff);
End.