K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

15 tháng 5 2020

cho e hỏi là tại sao dùng const fi fo vậy ạ ?

Bài 1:

const fi='mangmin.inp';

fo='mangmin.out';

var f1,f2:text;

a,vt:array[1..100]of integer;

n,i,dem:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,n);

for i:=1 to n do

read(f1,a[i]);

min:=a[1];

for i:=1 to n do

if min>a[i] then min:=a[i];

dem:=0;

for i:=1 to n do

if min=a[i] then

begin

inc(dem);

vt[dem]:=i;

end;

writeln(f2,'Gia tri nho nhat la: ',min);

writeln(f2,'Vi tri cua gia tri nho nhat la: ');

for i:=1 to dem do

write(f2,vt[i]:4);

close(f1);

close(f2);

end.

Bài 2:

const fi='mangchan.inp';

fo='mangchan.out';

var f1,f2:text;

a:array[1..100]of integer;

n,i,t:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,n);

for i:=1 to n do

read(f1,a[i]);

t:=0;

for i:=1 to n do

if a[i] mod 2=0 then t:=t+a[i];

writeln(f2,t);

close(f1);

close(f2);

end.

Bài 3:

const fi='tachxau.inp';
fo='tachxau.out';
var f1,f2:text;
s,s1,s2,s3,s4:string;
i,d:integer;
j,k,l:char;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,s);
d:=length(s);
s1:='';
for i:=1 to d do
if s[i] in ['0'..'9'] then s1:=s1+s[i];
writeln(f2,'Xau S1 la: ',s1);
s2:='';
for i:=1 to d do
if s[i] in ['a'..'z'] then s2:=s2+s[i];
writeln(f2,'Xau S2 la: ',s2);
s3:='';
for i:=1 to d do
if s[i] in ['A'..'Z'] then s3:=s3+s[i];
writeln(f2,'Xau S3 la: ',s3);
close(f1);
close(f2);
end.

Bài 4:

const fi='demtu.inp';
fo='demtu.out';
var s:string;
i,d,dem:integer;
kt:boolean;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,s);
d:=length(s);
i:=0;
while i<=d do
begin
inc(i);
if ((i=1) and (s[i]=' ')) then
repeat
kt:=false;
if (s[i]=' ') then
begin
delete(s,i,1);
d:=length(s);
end
else kt:=true;
until (kt=true) or (i+1>d)
else repeat
kt:=false;
if (s[i]=' ') and (s[i+1]=' ') then
begin
delete(s,i,1);
d:=length(s);
end
else kt:=true;
until (kt=true) or (i+1>d);
d:=length(s);
end;
while s[d]=' ' do
begin
delete(s,d,1);
d:=length(s);
end;
dem:=0;
for i:=1 to d do
if s[i]=' ' then dem:=dem+1;
writeln(f2,dem+1);
close(f1);
close(f2);
end.

const fi='input.txt';

fo='output.txt';

var f1,f2:text;

st:string[125];

a:array[1..125]of string;

i,d,dem,kt,j:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,st);

d:=length(st);

dem:=1;

a[1]:=st[1];

for i:=1 to d do

  begin

kt:=0;

for j:=1 to dem do 

  if a[j]=st[i] then kt:=1;

if kt=0 then 

begin

inc(dem);

a[dem]:=st[i];

end;

end;

for i:=1 to dem do 

  begin

dem1:=0;

for j:=1 to d do 

if a[i]=st[j] then inc(dem1);

writeln(f2,a[i],' xuat hien ',dem1,' lan');

end;

close(f1);

close(f2);

end.

const fi='vao.inp';

fo='ra.out';

var f1,f2:text;

st:string;

i,d:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,st);

d:=length(st);

for i:=1 to d do 

  if st[i]='a' then delete(st,i,1);

writeln(f2,st);

close(f1);

close(f2);

end.

const fi='kt.txt';

fo='kq.out';

var f1,f2:text;

s:string;

i,dem,d:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,s);

vt:=pos('anh',s);

while vt<>0 do

begin

delete(s,vt,3);

insert(s,vt,'em');

vt:=pos('anh',s);

end;

writeln(f2,s);

close(f1);

close(f2);

end.

uses crt;

const fi='xau.txt';

var f1:text;

s:string;

i,d,kt:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

readln(f1,s);

d:=length(s);

kt:=0;

for i:=1 to d do

if st[i]<>st[d-i+1] then kt:=1;

if kt=0 then writeln('Xau doi xung')

else writeln('Xau khong doi xung');

readln;

end.