作业帮 > 综合 > 作业

统计单词个数 pascal代码

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/05 15:40:50
统计单词个数 pascal代码
告诉
样例输入 Sample Input
Hello everybody!Vivian Snow is the greatest alive.
样例输出 Sample Output
8
时间限制 Time Limitation
1s
请无视Sample Input
var s:string;
    i,j,t:integer;
begin
  readln(s);
  for i:=1 to length(s) do
    if (s[i]<'A')and(s[i]>'Z')and(s[i]<'a')and(s[i]>'z')
       and(s[i]<>' ') then s[i]:=' ';
  j:=pos(' ',s);
  while j>0 do begin
    if s[j+1]=' ' then while s[j+1]=' ' do delete(s,j+1,1);
    j:=pos(' ',copy(s,j+1,255));
  end;
  j:=1;
  for i:=1 to length(s) do
    if s[i]=' ' then inc(j);
  writeln(j);
end.