0% found this document useful (0 votes)
30 views2 pages

Xau 23

The document contains code to standardize a string by removing duplicate spaces and leading/trailing spaces. It also contains code to count the number of occurrences of each character (A, B, C, D) in a given string. The code removes duplicate and leading/trailing spaces from an input string, writes the standardized string, and counts & writes the number of each character in a separate sample string.

Uploaded by

tinh_tnut
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Xau 23

The document contains code to standardize a string by removing duplicate spaces and leading/trailing spaces. It also contains code to count the number of occurrences of each character (A, B, C, D) in a given string. The code removes duplicate and leading/trailing spaces from an input string, writes the standardized string, and counts & writes the number of each character in a separate sample string.

Uploaded by

tinh_tnut
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

{ Bai 2 tach xau}

Program Xau_ChuanHoa;
Uses Crt;
Const Space = #32;
Var S,W: String;p:integer;
{ procedure tachtu( var td: string; dong:string);
var i:integer;
begin
i:=1;
td:=' ';
while((Upcase(dong[i]) <'A') or (upcase(dong[i]) >'Z')) and
(i<=length(dong)) do
i:=i+1;
while((upcase(dong[i]) >='A') and (upcase(dong[i])<='Z')) and
(i<=length(dong)) do
begin
td:=td+dong[i];i:=i+1;
end ;

end;}
Begin
ClrScr;
Write('Nhap mot xau: '); readln(s);
{ tachtu(W,s);
write(W);}
(* Bo cac khoang trang*)
Repeat
p := Pos(Space + Space, s); {Tim hai hai ky tu trang ke
nhau }
If p > 0 Then Delete(S, p, 1);
Until p = 0;
If S[1] = Space Then Delete(S, 1, 1);
If S[length(S)] = Space Then Dec(S[0]);
Write('Xau S = ', S);
Readln;
End.
{ Bai 3 nen xau}
Program Xau;
Var St: string;
dem,dem1,dem2,dem3,n,i: integer;
Begin
{ Write('Nhap xau St = '); Readln(St);} st:='AAABCCCDD';
n:= length(St);
Dem:=0;
For i:=1 to n do
If St[i] = 'A' then Dem:=Dem+1;
if st[0] = 'A' then dem:=dem+1;
Write('So chu A trong xau = ',Dem,'A');
For i:=1 to n do
If St[i] = 'B' then Dem1:=Dem1+1;
{if st[0] = 'B' then dem1:=dem1+1;}
Write(Dem1,'B');
For i:=1 to n do
If St[i] = 'C' then Dem2:=Dem2+1;
{if st[0] = 'C' then dem2:=dem1+1;}
Write(Dem2,'C');
For i:=1 to n do
If St[i] = 'D' then Dem3:=Dem3+1;
Write(Dem3,'D');
Readln;
End.

You might also like