Cod sursa(job #245625)

Utilizator j8rj72Giurgiu Adrian j8rj72 Data 18 ianuarie 2009 13:46:37
Problema Cifra Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.16 kb
program cifra;
var f1,f2:text; s:string; nr,s1,n,t,i:longint;
begin       
assign(f1,'cifra.in');        
reset(f1);        
assign(f2,'cifra.out');        
rewrite(f2);        
readln(f1,t);        
for i:=1 to t do begin       
readln(f1,s);        
n:=length(s);        
if n=1 then s1:=ord(s[1])-48       
else begin       
s1:=ord(s[n-1])-48;        
s1:=10*s1+(ord(s[n])-48);        
end;        
nr:=4*(s1 div 20);        
s1:=s1 mod 20;        
if s1>=1 then nr:=nr+1;        
if s1>=2 then nr:=nr+4;        
if s1>=3 then nr:=nr+7;        
if s1>=4 then nr:=nr+6;        
if s1>=5 then nr:=nr+5;        
if s1>=6 then nr:=nr+6;        
if s1>=7 then nr:=nr+3;        
if s1>=8 then nr:=nr+6;        
if s1>=9 then nr:=nr+9;        
if s1>=11 then nr:=nr+1;        
if s1>=12 then nr:=nr+6;        
if s1>=13 then nr:=nr+3;        
if s1>=14 then nr:=nr+6;        
if s1>=15 then nr:=nr+5;        
if s1>=16 then nr:=nr+6;        
if s1>=17 then nr:=nr+7;        
if s1>=18 then nr:=nr+4;        
if s1>=19 then nr:=nr+9;        
writeln(f2,nr mod 10);        
end;        
close(f1);        
close(f2);        
end.       
var f1,f2:text; s:string; nr,s1,n,t,i:longint;     
begin    
assign(f1,'cifra.in');     
reset(f1);     
assign(f2,'cifra.out');     
rewrite(f2);     
readln(f1,t);     
for i:=1 to t do begin    
readln(f1,s);     
n:=length(s);     
if n=1 then s1:=ord(s[1])-48    
else begin    
s1:=ord(s[n-1])-48;     
s1:=10*s1+(ord(s[n])-48);     
end;     
nr:=4*(s1 div 20);     
s1:=s1 mod 20;     
if s1>=1 then nr:=nr+1;     
if s1>=2 then nr:=nr+4;     
if s1>=3 then nr:=nr+7;     
if s1>=4 then nr:=nr+6;     
if s1>=5 then nr:=nr+5;     
if s1>=6 then nr:=nr+6;     
if s1>=7 then nr:=nr+3;     
if s1>=8 then nr:=nr+6;     
if s1>=9 then nr:=nr+9;     
if s1>=11 then nr:=nr+1;     
if s1>=12 then nr:=nr+6;     
if s1>=13 then nr:=nr+3;     
if s1>=14 then nr:=nr+6;     
if s1>=15 then nr:=nr+5;     
if s1>=16 then nr:=nr+6;     
if s1>=17 then nr:=nr+7;     
if s1>=18 then nr:=nr+4;     
if s1>=19 then nr:=nr+9;     
writeln(f2,nr mod 10);     
end;     
close(f1);     
close(f2);     
end.