Mã nguồn (Đếm số từ):
Mã: Chọn tất cả
Program DemTu;
Uses Crt;
Procedure Trim(Var St: AnsiString);
Begin
While (Length(St) > 0) And (St[1] = ' ') Do Delete(St, 1, 1);
While (Length(St) > 0) And (St[Length(St)] = ' ') Do Delete(St, Length(St), 1);
While (Length(St) > 0) And (Pos(' ', St) > 0) Do Delete(St, Pos(' ', St), 1);
End;
Var St : AnsiString;
Dem : Integer;
Begin
ClrScr;
Write('Nhap xau: ');
ReadLn(St);
Trim(St);
Dem := 0;
If Length(St) > 0 Then Begin
St := St + ' ';
While (Length(St) > 0) And (Pos(' ', St) > 0) Do Begin
Inc(Dem);
Delete(St, 1, Pos(' ', St));
End;
End;
Write('Ket qua: ', Dem);
ReadLn;
End.
Mã: Chọn tất cả
Program TuDaiNhat;
Uses Crt;
Procedure Trim(Var St: AnsiString);
Begin
While (Length(St) > 0) And (St[1] = ' ') Do Delete(St, 1, 1);
While (Length(St) > 0) And (St[Length(St)] = ' ') Do Delete(St, Length(St), 1);
While (Length(St) > 0) And (Pos(' ', St) > 0) Do Delete(St, Pos(' ', St), 1);
End;
Var St : AnsiString;
KQ : String;
Begin
ClrScr;
Write('Nhap xau: ');
ReadLn(St);
Trim(St);
KQ := '';
If Length(St) > 0 Then Begin
St := St + ' ';
While (Length(St) > 0) And (Pos(' ', St) > 0) Do Begin
If Pos(' ', St) - 1 > Length(KQ)
Then KQ := Copy(St, 1, Pos(' ', St) - 1);
Delete(St, 1, Pos(' ', St));
End;
End;
Write('Ket qua: ', KQ);
ReadLn;
End.