Đếm số lần xuất hiện của mỗi chữ cái trong xâu
Uses Crt;
Var St:String;
dem: Array[‘A’..’Z’] Of Byte;
i:Byte;
ch:Char;
Begin
Write(‘Nhap xau St: ‘); Readln(St);
{Khởi tạo mảng}
For ch:=’A’ To ‘Z’ Do dem[ch]:=0;
{Duyệt xâu}
For i:=1 To Length(St) Do
If Upcase(St[i]) IN [‘A’..’Z’] Then Inc(dem[Upcase(St[i])]);
{Liệt kê các ký tự ra màn hình}
For ch:=’A’ To ‘Z’ Do
If dem[ch]>0 Then Writeln(ch,’ : ’,dem[ch]);
Readln;
End.
0 nhận xét:
Đăng nhận xét
Click to see the code!
To insert emoticon you must added at least one space before the code.