Найти слово, предшествующее первому вхождению w в s1 (Составить блок-схему) - Turbo Pascal
Формулировка задачи:
Даны две строки s1 и s2. Пусть w – первое из слов строки s1, которое есть и в строке s2. Найти слово, предшествующее первому вхождению w в s1.
Решение задачи: «Найти слово, предшествующее первому вхождению w в s1 (Составить блок-схему)»
textual
Листинг программы
const n = 3; type strings = array [0..n] of string; var s1,s2 : string; findstr : string; wordsS1 : strings; wordsS2 : strings; i,j : integer; procedure escapingWordsFromString (str:string; var words: strings); var tempstring: string; tempint: integer; ind:integer; begin tempint := 1; tempstring := ''; for ind:=1 to length(str)+1 do begin if (ind = length(str)+1) then begin words[tempint] := tempstring; tempint := tempint + 1; tempstring := ''; continue; end else if (str[ind] = ' ') then begin words[tempint] := tempstring; tempint := tempint + 1; tempstring := ''; continue; end; tempstring := tempstring + str[ind]; end; end; begin findStr := ''; s1 := 'wadkl fiwthword qwerty'; s2 := 'secondword thirtyword fourtyword fiwthword qwerty'; escapingWordsFromString(s1,wordsS1); escapingWordsFromString(s2,wordsS2); for i:=1 to n do begin for j:=1 to n do begin if (wordsS1[i] = wordsS2[j]) then if (i > 1) then begin findStr := wordsS1[i-1]; writeln('--------'); writeln('Founded word is ', findStr); exit; end else begin writeln('--------'); writeln('Not founded!'); exit; end; end; end; end.
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д