Pagini recente » Cod sursa (job #2552982) | Cod sursa (job #999511) | Cod sursa (job #2403016) | Cod sursa (job #327393) | Cod sursa (job #13877)
Cod sursa(job #13877)
{ problema cifra - infoarena.ro}
program cifra_infoarena;
type sir=array[1..3000] of longint;
var n:longint;
f,g:text;
c,cif,ult:byte;
a:sir;
i,t:longint;
procedure citire(var a:sir);
begin
assign(f,'cifra.in'); reset(f);
readln(f,t);
for i:=1 to t do readln(f,a[i]);
close(f);
end;
procedure cifra(n:longint);
var p:longint;
k,i1:longint;
begin
ult:=0;
for i1:=1 to n do begin
c:=i1 mod 10;
if c=1 then cif:=1
else
if c=2 then
case i1 mod 4 of
0:cif:=6;
1:cif:=2;
2:cif:=4;
3:cif:=8;
end
else
if c=3 then
case i1 mod 4 of
0:cif:=1;
1:cif:=3;
2:cif:=9;
3:cif:=7;
end
else
if c=4 then
case i1 mod 2 of
0:cif:=6;
1:cif:=4;
end
else
if c=5 then cif:=5
else
if c=6 then cif:=6
else
if c=7 then
case i1 mod 4 of
0:cif:=7;
1:cif:=9;
2:cif:=3;
3:cif:=1;
end
else
if c=8 then
case i1 mod 4 of
0:cif:=8;
1:cif:=4;
2:cif:=2;
3:cif:=6;
end
else
if c=9 then
case i1 mod 2 of
0:cif:=1;
1:cif:=9;
end;
ult:=(ult+cif)mod 10;
end;
end;
begin
citire(a);
assign(g,'cifra.out'); rewrite(g);
for i:=1 to t do begin
if a[i]<maxlongint then begin
cifra(a[i]);
writeln(g,ult);
end;
end;
close(g);
end.