pascal 句子问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 15:46:08
问题描述:
输入一个英文句子,例如:“This is a book.”可以看到句子是以“.”来做结束符号的。
并且单词之间以一个空格来分隔。接着输入一个单词A,请找出首次在句子中出现的与A$相同的单词,是句子中的第几个单词,若不存在,则输出该句子中单词字符的总个数(不计空格)。
例如对上句子而言:若输入单词“is”,则输出2
若输入单词“isa”则输出11
样例输入:This is a book.
is
输出:2

program juzi;
var a,b,x:string;
i,s,l:integer;
ch:char;
c:array[1..100] of integer;
begin
repeat
read(ch);
a:=a+ch;
if ch=' ' then begin l:=l+1; c[l+1]:=length(a); end;
until ch='.';
readln;
read(b);
c[1]:=0;
for i:=1 to l-1 do
begin
x:=copy(a,c[i]+1,c[i+1]-c[i]-1);
if x=b then begin writeln(i); exit; end;
end;
writeln(l+1);
end.