bài 1 hình như có công thức tìm khoảng cách 2 điểm
A(x1,y1) và B(x2,y2) thì AB=[tex]\sqrt{(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)}[/tex] rồi tìm max thôi
bài 2: chạy cho tới khi thấy ' ' dừng lại trước đó sẽ là họ tìm từng cái 1 rồi lại tìm max
bài 3: chạy từ 1 cho tới n rồi đếm nếu a[ i ]mà chia hết cho k thì +1 mà không thì đếm quay lại =0 lại tìm max trong các lần đếm
program doKhoangCach;
var a, b, x, y: integer;
khcach, max: real;
t: text;
begin
assign(t,'TRAI.TXT');
reset(t);
read(t,a,b);
khcach := 0;
while not eof(t) do
begin
read(t,x,y);
khcach := sqrt(sqr(a-x)+sqr(b-y));
if khcach > max then max := khcach;
end;
close(t);
assign(t,'KCMAX.OUT');
rewrite(t);
write(t,max:0:5);
close(t);
end.
2. (Giả sử không có hai học sinh có họ khác nhau nhưng có cùng độ dài dài nhất) (lười viết)
Mã:
program hoTenDaiNhat;
var s, ho, homax: string;
max: byte;
t: text;
begin
assign(t,'XAU.INP');
reset(t);
max:= 0;
while not eof(t) do
begin
readln(t,s);
ho:= copy(s,1,pos(' ',s)-1);
if length(ho) > max then
begin
max:= length(ho);
homax:= ho;
end;
end;
close(t);
assign(t,'XAU.OUT');
rewrite(t);
writeln(t,max);
write(t,homax);
close(t);
end.
3.
Mã:
program doDaiChuoi;
var A: array[1..100] of integer;
t: text;
n, k, i, j, max: integer;
begin
assign(t,'SUBSEQ.INP');
reset(t);
read(t,n,k);
max:=0;
for i:=1 to n do read(t,A[i]);
for i:=1 to n do
begin
j:=0;
while (A[i+j] mod k = 0) and (i+j <= n) do
j:=j+1;
if j > max then max:=j;
end;
close(t);
assign(t,'SUBSEQ.OUT');
rewrite(t);
write(t,max);
close(t);
end.