pc.bt2

Màu nền
Font chữ
Font size
Chiều cao dòng

BT2 :Lập Ct thực hiện các công việc sau:

a)Nhập vào một xâu.

b)Thực hiện chuẩn hóa xâu in ra kết quả.

c)cho biết số từ của xâu.

d)Cho biết tỷ lệ % của số từ đơn âm trong xâu.

E)Đổi xâu sang kí tự thường.

program xau;

var     s:string;stu,i,dau,cuoi,sdam:integer;

function cattron(s:string):string;

var      i:integer;

begin

     i:=1;

     while s[i]=#32 do i:=i+1;

     delete (s,1,i-1);

     cattron:=s;

     end;

function catphai(s:string):string;

var      j:integer;

begin

     i:=length(s);

     while s[i]=#32 do i:=i-1;

     j:=i;s:=copy(s,1,i);

     {caption:=s;}

end;

function catgiua(s:string):string;

var i:integer;

begin

     i:=pos(#32#32,s);

     while i<>0 do

     begin

          delete(s,i,1);

          i:=pos(#32#32,s);

     end;

catgiua:=s;

end;

function demtu(s:string):integer;

begin

     s:=#32+s;d:=0;

     for i:=1 to length(s)-1 do

     if(s[i]=#32)and(s[i+1]<>#32 then

     d:=d+1;

end;

return:=d;

end;

function songuyenam(tu:string):integer;

var

begin

     s:=['A','E','O','U','I']

     d:=0

     for i:=1 to length(tu) do

     if(upcase(tu[i])in s then d:=d+1;

     songuyenam:=d;

end;

program chuanhoaxau;

begin

     s:=cattron(s);

     s:=catphai(s);

     s:=catgiua(s);

     writeln('xau dc chua hoa:',s);

end;

procedure hoathuong(s);

var i:integer;

begin

     for i:=1 to length(s) do

     if(s[i]>=#65 and s[i]<=#90) then

     s[i]:=chr(ord(s[i]+32));

     writeln("xau dc doi sang thuong la:',s);

end;

begin readln(s);

chuanhoa(s);

stu:=demtu(s);

writeln('so tu trong xau la:');

i:=0;

repeat

      repeat i:=i+1

      until s[i]<>#32,dau=i;

      repeat i:=i+1

             tu:=copy(s,dau,cuoi-dau+1);

             if songuyenam(tu)=1 then sdam=sdam+1

      until i>length(s)

      writeln;

      writeln('ty le % cua so tu don am la:',sdam/stu*100);

      hoathuong(s);

end.

{thu tuc xd chinh phuong, hoan hao}

function chinhphuong(p:integer):boolean;

var i:integer;

begin

     chinhphuong:=false;

     for i:=1 to p dix 2 do

     if i*i=p then chinhphuong:=true;

end;

function hoanhao(p:integer):boolean;

var i,s:integer;

begin

     s:=1;

     for i:=2 to p div 2 do

     if(p mod i=0)then s:=s+i;

     hoanhao:=s=p;

end;

if s=p then hoanhao:=true

else hoanhao:=false;

end;

Bạn đang đọc truyện trên: Truyen2U.Pro