Thứ Sáu, 7 tháng 12, 2018

Ví dụ về chương trình con (có cấu trúc)


const
   fin='test.inp';   fon='test.out';
   maxmn=1000;maxn=1000;
   vc=maxlongint;

var
   cs:array[0..9] of string;
   n,d:longint;
procedure nhap;
var i:Longint;s:string; c:char;
begin
d:=-1;s:='';
while not eoln do
   begin
   read(c);
   if c<>' ' then s:=s+c
   else
      begin inc(d);cs[d]:=s;s:=''; end;
   end;
end;

function doccs(x:longint):string;
var max:string;
begin
max:=cs[x mod 10];
while x>0 do
   begin
   if cs[x mod 10]>max then max:=cs[x mod 10];
   x:=x div 10;
   end;
exit(max);
end;

procedure xuli;
var s,i,x:longint;
begin
read(n);
for i:=1 to n do
   begin
   read(x);
   writeln(doccs(x));
   end;
end;

begin
assign(input,fin);reset(input);
assign(output,fon);rewrite(output);
nhap;
xuli;
close(input);close(output);
end.

0 nhận xét:

Đăng nhận xét