Cod sursa(job #1977677)

Utilizator math4Bornea Andrei Laurentiu math4 Data 5 mai 2017 20:22:41
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.38 kb
var f,g:text;
    s,p,i,x,n,j:longint;

begin
assign(f,'cifra.in');
assign(g,'cifra.out');
reset(f);
rewrite(g);
read(f,n);
for j:=1 to n do
begin
s:=0;
read(f,x);
for i:=1 to x do
begin
p:=i mod 10;
if p=1 then s:=(s+1) mod 10;
if p=0 then s:=(s+0) mod 10;
if p=5 then s:=(s+5) mod 10;
if p=6 then s:=(s+6) mod 10;
if p=2 then
begin
if i mod 4=1 then s:=(s+2) mod 10;
if i mod 4=2 then s:=(s+4) mod 10;
if i mod 4=3 then s:=(s+8) mod 10;
if i mod 4=0 then s:=(s+6) mod 10;
end;
if p=3 then
begin
if i mod 4=1 then s:=(s+3) mod 10;
if i mod 4=2 then s:=(s+9) mod 10;
if i mod 4=3 then s:=(s+7) mod 10;
if i mod 4=0 then s:=(s+1) mod 10;
end;
if p=7 then
begin
if i mod 4=1 then s:=(s+7) mod 10;
if i mod 4=2 then s:=(s+9) mod 10;
if i mod 4=3 then s:=(s+3) mod 10;
if i mod 4=0 then s:=(s+1) mod 10;
end;
if p=8 then
begin
if i mod 4=1 then s:=(s+8) mod 10;
if i mod 4=2 then s:=(s+4) mod 10;
if i mod 4=3 then s:=(s+2) mod 10;
if i mod 4=0 then s:=(s+6) mod 10;
end;
if p=4 then
begin
if i mod 4=1 then s:=(s+4) mod 10;
if i mod 4=2 then s:=(s+6) mod 10;
if i mod 4=3 then s:=(s+4) mod 10;
if i mod 4=0 then s:=(s+6) mod 10;
end;
if p=9 then
begin
if i mod 4=1 then s:=(s+9) mod 10;
if i mod 4=2 then s:=(s+1) mod 10;
if i mod 4=3 then s:=(s+9) mod 10;
if i mod 4=0 then s:=(s+1) mod 10;
end;
end;
writeln(g,s);
end;
close(f);
close(g);
end.