Cod sursa(job #59424)

Utilizator h_istvanHevele Istvan h_istvan Data 9 mai 2007 09:17:03
Problema Cifra Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.33 kb
program cifra;
const szjegy:array[1..9] of byte = (1,4,7,6,5,6,3,6,9);
      temp:array[1..9] of byte = (0,1,1,0,0,0,1,1,0);
var f,fout:text;
    t,i,j,x,y:word;
    sz:string;
    v:array[0..9,0..9] of longint;

function megold:byte;
var  i:byte;
     e,t:word;
begin
     e:=0;
     for i:=1 to 9 do
     begin
          t:=(ord(sz[length(sz)-1])-48);
          if(ord(sz[length(sz)])-48 >= i) then t:=t+1;

          if(temp[i] = 0) then
          begin
               e:=e+(t*szjegy[i]) mod 10;
               e:=e mod 10;
          end else
          begin
               if(t mod 2 = 1) then e:=e+szjegy[i];
               e:=e mod 10;
          end;
     end;
     megold:=e;
end;

begin
     sz:='';
     for i:=0 to 9 do
     begin
          sz:=chr(i+48);
          for j:=0 to 9 do
          begin
               sz:=sz+chr(j+48);
               v[i,j]:=megold;
               sz:=chr(i+48);
          end;
     end;

     assign(f,'cifra.in');
     assign(fout,'cifra.out');
     reset(f);
     rewrite(fout);
     readln(f,t);
     for i:=1 to t do
     begin
          readln(f,sz);
          if(length(sz)=1) then insert('0',sz,1);
          x:=ord(sz[length(sz)-1])-48;
          y:=ord(sz[length(sz)])-48;
          writeln(fout,v[x,y]);
     end;
     close(f);
     close(fout);
end.