A sequence of integers a1, a2, ..., a18 is given, at the beginning of which several equal elements are written together. Determine the number of such elements of the sequence. Conditional statement and arrays do not use. Use the loop operator with the condition.

program reflect; var s, k, n, m: integer; begin readln(s); n := 1; repeat readln(k); m := n; while (s = k) and (n = m) do inc(n) until (s <> k) or (n >= 18); for m := n + 1 to 17 do readln(s); writeln; writeln(n); readln end. 

Can you please interpret this program? by action)

Closed due to the fact that off-topic participants Mikhail Vaysman , user194374, Denis Bubnov , Nicolas Chabanovsky 20 Feb '17 at 8:20 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Mikhail Vaysman, Community Spirit, Denis Bubnov, Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The master visited the 9th line) It says if s=k then inc(n) - vp_arth
  • You can also while (s=k) do begin inc(n); break; end; while (s=k) do begin inc(n); break; end; - vp_arth

1 answer 1

 program reflect; var s, k, n, m: integer; begin readln(s); //считывает число введённое с клавиатуры n := 1; repeat readln(k); //считывает второе число пока не выйдет из цикла m := n; // while (s = k) and (n = m) do inc(n) //пока последующие числа равны первому увеличивает (inc) счётчик n на +1. (n = m) нужен для выхода из этого цикла. until (s <> k) or (n >= 18); //выход из цикла если следующее число неравно первому или введено 17 раз for m := n + 1 to 17 do readln(s); //продолжить считывать ввод оостальных чисел но ничего с ними не делать writeln; writeln(n); //написать количество совпадений. количество введённых n совпадающих с s readln end.