fork download
  1. program lab8txt(input, output);
  2.  
  3. var
  4. str: string;
  5. A: array[1..100] of integer;
  6. i, k: integer;
  7.  
  8. procedure mysearch(str: string; var k: integer);
  9. var
  10. i: integer;
  11. begin
  12. k := 0;
  13. for i := 1 to length(str)-3 do
  14. if (str[i] = 't') and (str[i+1] = 'h') and
  15. (str[i+2] = 'e') and (str[i+3] = 'n') then
  16. k := k + 1;
  17. end;
  18.  
  19. begin
  20. i := 1;
  21. repeat
  22. readln(str);
  23. if str <> '' then
  24. begin
  25. mysearch(str, A[i]);
  26. writeln('Кількість then у рядку', i, ': ', A[i]);
  27. i := i + 1;
  28. end;
  29. until str = '';
  30. end.
Success #stdin #stdout 0s 5304KB
stdin
We will test this code now, then check all options, then run the script again, then see the result
We will read the input string first, then search for the pattern. then, we can output the final count to the console
If you want to improve your code, then you should test it carefully. If all tests pass, then we can merge the changes.
stdout
Кількість then у рядку1: 3
Кількість then у рядку2: 2
Кількість then у рядку3: 2