1) Trong PASCAL de khai bao bien tep van ban ta phai su dung cu phap:
A. Var<ten bien tep>: Text; B. Var <ten tep>: Text;
C. Var <ten tep> : String; D. Var <ten bien tep> : String;
1) Neu ham eoln( ) cho gia tri bang true thi con tro tep nam o vi tri:
A. Dau dong B. Dau tep C. Cuoi dong D. Cuoi tep
Cho khai báo sau:
Var a,b:array[1..5]of real;
Tổng bộ nhớ trong khai báo trên là:
A. 60 byte
B. 48 byte
C. 24 byte
D. 30 byte
1) Cau lenh Rewrite(<bien tep>); co y nghia gi
A. Thu tuc gan ten tep cho ten bien tep B. Khai bao bien tep
C. Thu tuc dong tep D. Thu tuc mo ten de ghi du lieu
1) Cau lenh Assign(<bien tep>, <ten tep>); co y nghia gi
A. thu tuc gan ten tep cho ten bien tep B. thu tuc mo ten de doc du lieu
C. Khai bao bien tep D. Thu tuc dong tep
1) Khi viet mot chuong trinh muon tra ve 1 gia tri ta nen dung:
A. Ham B. Thu tuc C. Chuong trinh con D. Thu tuc hoac ham
1) Chuong trinh con gom co:
A. Ham va thu tuc B. Hang va bien
C. Ham va hang D. Thu tuc va bien
1) Dien vao dau cham trong bai giai: Viet chuong trinh thuc hien nhung viec sau:
a) Doc tu ban phim 1 danh sach gom:
Ho ten, mon thi thu nhat, diem mon thi thu nhat , mon thi thu hai, diem mon thi thu hai
b) Ghi vao dia voi ten tep QLHT
c) Doc du lieu tu File QLHT, tim nhung hoc sinh phai thi lai ( co it nhat mot mon khong dat ) . Dua ra so thu tu, ho ten, cac mon phai thi lai va diem tuong ung ra man hinh
Bai giai
program......
Uses Crt;
type phieudiem = record
hten : string [25];
Mh1 : string [10];
d1 : real;
Mh2 : string [10];
d2 : real'
end;
Var
pd : phieudiem;
f file of phieudiem;
n,i,t : integer;
Begin
clrscr;
write ( ' So phieu diem n = ' ) ;
...........................
assign (....................) ;
rewrite (..............)
For i := 1 to n do
with pd do
begin
Writeln ( ' Vao phieu diem thu ' , i );
Write ( ' Ho va ten: ' ) ;
Readln (...................)
Write (' Mon thi thu nhat : ') ;
Read..............
Write ( ' Diem mon thu nhat ' );
Read.....................
Write ( ' Mon thi thu hai: ' ) ;
Readln.............................
Write ( ' Diem mon thu hai: ' ) ;
Read...............
Write ( f, pd ) ;
end;
close (f);
clrscr ;
Writeln ( ' Danh sach hoc sinh thi lai : ') ;
Writeln;
assign....................
reset...........
t : = 0 ;
While not eof (f) do
Begin
read ( r, pd );
with pd do
If ( d1 < 5 ) or ( d2 < 5 ) then
Begin
inc (t);
Write..................
if d1 < 5 then
Write.......
if d2 < 5 then
Write............
Writeln;
end;
end;
close (f);
end.
ĐÁP ÁN VÒNG 1 CUỘC THI TIN HỌC LẦN 2
Câu 1:
const fi='ptyn.inp'
fo='ptyn.out'
var a:array[1..100,1..100]of integer;
i,j,n,m,snn,sln,vtc,vth,x,z,kt,k,dem:integer;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,m);
for i:=1 to n do
for j:=1 to m do
read(f1,a[i,j]);
{----------nho nhat hang----------}
dem:=0;
for i:=1 to n do
begin
snn:=a[i,1];
for j:=1 to m do
if snn>=a[i,j] then
begin
snn:=a[i,j];
vth:=i;
vtc:=j;
end;
kt:=0;
sln:=a[vth,vtc];
for k:=1 to n do
if sln<a[k,vtc] then kt:=1;
if kt=0 then
begin
writeln(f2,vth,' ',vtc);
dem:=dem+1;
end;
end;
if dem=0 then writeln(f2,'Khong co phan tu yen ngua');
close(f1);
close(f2);
end.
Câu 2: Bài làm của bạn @Tran Nguyễn Đăng Dương
Program connect;
uses crt;
const fi='connect.inp'
fo='connect.out'
type num=record
number,top:integer;
end;
var a:array[0..1000] of num;
t:num;
i,n,j:integer;
f1,f2:text;
Function timtop(a:integer):integer;
begin
if a<10 then exit(a);
exit(timtop(a div 10));
end;
Begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
read(f1,n);
for i:=1 to n do
begin
read(f1,a[i].number);
a[i].top:=timtop(a[i].number);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if a[i].top=a[j].top then
begin
if a[i].number>a[j].number then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
end
else if a[i].top<a[j].top then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
end;
for i:=1 to n do write(f2,a[i].number);
Close(f1);
Close(f2);
End.
Câu 3:
const fi='quediem.inp'
fo='quediem.out'
var f1,f2:text;
i,m,n,d,x,j,csc:longint;
a,b:array[1..100]of integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
{---------------------------tim-so-lon-nhat----------------------------}
m:=n;
if m mod 2=0 then
begin
for i:=1 to n div 2 do
write(f2,'1');
end
else begin
write(f2,'7');
for i:=2 to n div 2 do
write(f2,'1');
end;
{---------------------------tim-so-nho-nhat----------------------------}
write(f2,'-');
a[1]:=2; b[1]:=1;
a[2]:=5; b[2]:=2;
a[3]:=4; b[3]:=4;
a[4]:=6; b[4]:=6;
a[5]:=3; b[5]:=7;
a[6]:=7; b[6]:=8;
d:=(n div 7)+1;
if n mod 7=0 then d:=d-1;
if d=1 then
begin
case n of
2: write(f2,'1');
3: write(f2,'7');
4: write(f2,'4');
5: write(f2,'2');
6: write(f2,'0');
7: write(f2,'8');
end;
end;
if d>1 then
begin
for i:=1 to d do
if i=1 then
begin
b[4]:=6;
for j:=1 to 6 do
begin
x:=n;
x:=x-a[j];
csc:=(x div 7)+1;
if x mod 7=0 then dec(csc);
if csc=d-i then
begin
write(f2,b[j]);
n:=x;
break;
end;
end;
end
else begin
a[1]:=6; b[1]:=0;
a[2]:=2; b[2]:=1;
a[3]:=5; b[3]:=2;
a[4]:=4; b[4]:=4;
a[5]:=3; b[5]:=7;
a[6]:=7; b[6]:=8;
for j:=1 to 6 do
begin
x:=n;
x:=x-a[j];
csc:=(x div 7)+1;
if x mod 7=0 then csc:=csc-1;
if csc=d-i then
begin
write(f2,b[j]);
n:=x;
break;
end;
end;
end;
end;
close(f1);
close(f2);
end.
Câu 4:
const fi='tvh.inp'
fo='tvh.out'
var n,d,dem,sl,s2cs,s3cs,s4cs,s5cs,s6cs,s7cs,s8cs,k,i,d1:longint;
st,st1,stk:string;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,k);
str(n,st);
d:=length(st);
case d of
1: write(9);
2: begin
sl:=n-9;
dem:=9+sl*2;
end;
3: begin
s2cs:=(99-10)+1;
s3cs:=n-99;
dem:=9+s2cs*2+s3cs*3;
end;
4: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=n-999;
dem:=9+s2cs*2+s3cs*3+s4cs*4;
end;
5: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=n-9999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5;
end;
6: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=n-99999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6;
end;
7: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=(999999-100000)+1;
s7cs:=n-999999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6+s7cs*7;
end;
8: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=(999999-100000)+1;
s7cs:=(9999999-1000000)+1;
s8cs:=n-9999999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6+s7cs*7+s8cs*8;
end;
end;
if k<=dem then
begin
i:=1;
d1:=0;
repeat
str(i,st1);
d1:=d1+length(st1);
inc(i);
until d1>=k;
stk:=st1[length(st1)-(d1-k)];
writeln(f2,stk);
end;
close(f1);
close(f2);
end.
Câu 5: Bài làm của bạn @Tran Nguyễn Đăng Dương
Program robot;
uses crt;
const fi='robot.inp'
fo='robot.out'
type path=record
num,npath:integer;
end;
var a:array[0..1000,0..1000] of path;
i,j,n:integer;
b,c:array[1..2] of Integer;
st,st1:string;
f1,f2:text;
check:boolean;
min:real;
Function he2sanghe10(st1:string):real;
var d,x,tg:integer;
stt:string;
begin
he2sanghe10:=0;
d:=Length(st1);
for i:=1 to d do
begin
stt:=st1[i];
Val(stt,x,tg);
he2sanghe10:=he2sanghe10*2+x;
end;
end;
Procedure robotpath(x,y:integer; st1:string);
var k:integer;
t:string;
S:real;
begin
if (x=n) and (y=n) then
begin
S:=0;
S:=he2sanghe10(st1);
if (min>S) then
begin
min:=S;
st:=st1;
end;
end
else
for k:=1 to 2 do
begin
if (x+b[k]>=1) and (y+c[k]>=1) and (x+b[k]<=n) and (y+c[k]<=n) then
begin
str(a[x+b[k],y+c[k]].num,t);
st1:=st1+t;
a[x+b[k],y+c[k]].npath:=a[x,y].npath+1;
robotpath(x+b[k],y+c[k],st1);
Delete(st1,Length(st1),1);
if (a[x+b[k],y+c[k]].npath=0) then break;
end;
end;
end;
Begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
b[1]:=1; c[2]:=1;
min:=99999999999999999999999999999999999999;
read(f1,n);
for i:=1 to n do
for j:=1 to n do
begin
read(f1,a[i,j].num);
a[i,j].npath:=n*n;
end;
a[1,1].npath:=1;
Str(a[1,1].num,st1);
robotpath(1,1,st1);
writeln(f2,st);
Close(f1);
Close(f2);
End.