Lập trình đơn giản

Minh Lệ

ĐÁP ÁN VÒNG 1 CUỘC THI TIN HỌC

Câu 1:

const fi='tong.inp'

fo='tong.out'

var

f:text;i,n:integer;t:real;

procedure ip;

begin

assign(f,fi);

reset(f);

readln(f,n);

t:=abs(sqrt(4)*1/2);

for i:= 1 to n do

t:=t+(i/(i+1));

close(f);

end;

procedure out;

begin

assign(f,fo);

rewrite(f);

write(f,t:0:3);

close(f);

end;

BEGIN

ip;

out;

END.

Câu 2: Bài làm của bạn Lê Hoàng Thắng :

var a:array[1..10000000] of longint; min,vtmin,vtmax,n,i,k,demk,max,sum:longint; sm:boolean;
function nguyento(x:longint):boolean;
var demuoc,t:longint;
begin
demuoc:=0;
for t:=1 to x do if (x mod t = 0) then inc(demuoc);
if demuoc=2 then nguyento:=true else nguyento:=false;
end;
function hoanhao(y:longint):boolean;
var tong,g:longint;
begin
tong:=0;
for g:=1 to y-1 do if (y mod g=0) then tong:=tong+g;
if tong=y then hoanhao:=true else hoanhao:=false;
end;
begin
assign(input,'mang.inp'); reset(input);
assign(output,'mang.out'); rewrite(output);
readln(n); readln(k); demk:=0;
for i:=1 to n do read(a[i]);
min:=a[n];
for i:=n downto 1 do if a[i]<min then begin min:=a[i]; vtmin:=i; end;
max:=abs(a[1]);
for i:=1 to n do if abs(a[i])>max then begin max:=abs(a[i]); vtmax:=i; if a[i]<0 then sm:=true else sm:=false; end;
for i:=1 to n do if (k=a[i]) then inc(demk);
sum:=0;
for i:=1 to n do
begin
if (nguyento(a[i]) or hoanhao(a[i])) then sum:=sum+a[i];
end;
writeln(vtmin);
if sm=false then writeln(max,' ,vi tri: ',vtmax) else writeln('-',max,' ,vi tri: ',vtmax);
if (demk=0) then writeln('khong, so lan xuat hien :0') else writeln('co, so lan xuat hien :',demk);
write(sum);
close(input); close(output);
end.

Câu 3: Bài làm của bạn Lê Hoàng Thắng:

const fi='xau.inp'

fo='xau.out'

var s1,s2:string; match,i:longint; f: text;

procedure ip;

begin
assign(f,fi); reset(f);
readln(s1); read(s2);

close(f);

end;

procedure out;

begin

assign(f,fo); rewrite(f);
match:=0;
if s1=s2 then begin write('KHONG'); exit; end;
for i:=1 to length(s1) do
begin
if s1[i]=s2[i] then inc(match);
end;
if match=length(s1)-2 then write('CO') else write('KHONG');
close(f);

end;

Begin

ip;

out;
end.

Câu 4: Bài làm của bạn Đào Xuân Sơn :

const fi='STN.inp'
fo='STN.out'
var
f:text;
s:string;
n,t,i:integer;
function dx(x:string):boolean;
var
i:byte;
begin
dx:=false;
for i:= 1 to length(x) div 2 do
if x[i] <> x[length(x)-i+1] then
exit;
dx:=true;
end;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,n);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
str(n,s);
if dx(s) = true then writeln(f,'CO') else writeln(f,'KHONG');
t:=0;
for i:= 1 to n div 2 do
if n mod i = 0 then t:=t+i;
if t=n then
begin
write(f,'CO,');
t:=0;
while n<>0 do
begin
t:=t+(n mod 10);
n:=n div 10;
end;
writeln(f,' ',t);
end else
writeln(f,'KHONG');
write(f,length(s));
close(f);
end;
BEGIN
ip;
out;
END.

Bài 5: Bài làm của bạn Vinh Lê:

const fi=’tich.inp’;

fo=’tich.out’;

var f: text;

a,b: integer;

procedure ip;

begin

assign(f,fi);

reset(f);

readln(f,a);

read(b);

close(f);

procedure out;

begin

assign(f,fo);

rewite(f);

t:=a;

t:=t*b;

write(f,t);

close(f);

end;

Begin

ip;

out;

end.

Đây là các bộ code sử dụng thuật toán hoàn chỉnh nhất và tối ưu.

vũ lê đức anh
25 tháng 7 2019 lúc 20:15

thiệt ko vậy

Bình luận (0)

Các câu hỏi tương tự
Nguyễn Minh Lệ
Xem chi tiết
Quốc Thịnh ILF
Xem chi tiết
Nguyễn Minh Lệ
Xem chi tiết
Ba chú heo con
Xem chi tiết
Phan Nhật
Xem chi tiết
NHÓC BOSS GAMING
Xem chi tiết
Cold Wind
Xem chi tiết
nguyen ngoc minh chau
Xem chi tiết
Ho Truong Minh
Xem chi tiết