Cod sursa(job #143002)

Utilizator antoanelaAntoanela Siminiuc antoanela Data 25 februarie 2008 20:02:35
Problema Cifra Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.17 kb
program cifra;
var f,g:text;
    n,t,j,i,ci,p:longint;
    x,y:char;
begin
assign(f,'cifra.in');
assign(g,'cifra.out');
reset(f);
rewrite(g);
readln(f,t);
for j:=1 to t do
  begin
    x:='a';
    while not eoln(f) do
      begin
        y:=x;
        read(f,x);
      end;
    readln(f);
    if (y<>'a')then
      n:=(ord(y)-ord('0'))*10+ord(x)-orD('0') else
      n:=ord(x)-ord('0');
    p:=0;
    for i:=1 to n do
      begin
        ci:=i mod 10;
        if (ci=0)then p:=p+0 else
        if (ci=1)then p:=p+1 else
        if (ci=2)then
          begin
            if (i mod 4=0)then
              p:=p+6 else
            if (i mod 4=1)then
              p:=p+2 else
            if (i mod 4=2)then
              p:=p+4 else
            if (i mod 4=3)then
              p:=p+8;
          end else
        if (ci=3)then
          begin
            if (i mod 4=0)then
              p:=p+1 else
            if (i mod 4=1)then
              p:=p+3 else
            if (i mod 4=2)then
              p:=p+9 else
            if (i mod 4=3)then
              p:=p+7;
          end else
        if (ci=4)then
          begin
            if (i mod 2=0)then
              p:=p+6 else
            if (i mod 2=1)then
              p:=p+4;
          end else
        if (ci=5)then p:=p+5 else
        if (ci=6)then p:=p+6 else
        if (ci=7)then
          begin
            if (i mod 4=0)then
              p:=p+1 else
            if (i mod 4=1)then
              p:=p+7 else
            if (i mod 4=2)then
              p:=p+9 else
            if (i mod 4=3)then
              p:=p+3;
          end else
        if (ci=8)then
          begin
            if (i mod 4=0)then
              p:=p+6 else
            if (i mod 4=1)then
              p:=p+8 else
            if (i mod 4=2)then
              p:=p+4 else
            if (i mod 4=3)then
              p:=p+2;
          end else
        if (ci=9)then
          begin
            if (i mod 2=0)then
              p:=p+1 else
            if (i mod 2=1)then
              p:=p+9;
          end;
        p:=p mod 10;
      end;
    writeln(g,p);
  end;
close(f);
close(g);
end.