uses crt;
var X:string;
demtu,demdc,i:word;
begin
clrscr;
write('nhap cau van X:');readln(X);
writeln('so ki tu la:',length(X));
demtu:=1;
for i:=1 to length(X)-1 do
if (X[i]<>' ') and (X[i+1]=' ') then demtu:=demtu+1;
writeln('so tu la:',demtu);
demdc:=0;
for i:=1 to length(X) do
if X[i]=' ' then demdc:=demdc+1;
writeln('so dau cach la:',demdc);
readln;
end.
bài này mới đúng nè bạn:
uses crt;
var X:string;
demtu,demdc,i:word;
begin
clrscr;
write('nhap cau van X:');readln(X);
writeln('so ki tu la:',length(X));
X:=X+' ';
demtu:=0;
for i:=1 to length(X)-1 do
if (X[i]<>' ') and (X[i+1]=' ') then demtu:=demtu+1;
writeln('so tu la:',demtu);
delete(X,length(X),1);
demdc:=0;
for i:=1 to length(X) do
if X[i]=' ' then demdc:=demdc+1;
writeln('so dau cach la:',demdc);
readln;
end.