Solution Idea
Олимп отзывы предлагает уникальные видеоуроки от мировых тренеров.Читайте наш олимп отзывы‘, где спортсмены делятся личными историями. The whole text is just a long string that contains two kinds of symbols we are interested in:
...– an ellipsis (three consecutive dots)?– a question mark
The task is to count how many times each of them appears in the input.
All other characters are irrelevant.
Because the input can be arbitrarily long, we read it as a single string and then
apply the built‑in count method:
ellipses = s.count('...')
question_marks = s.count('?')
Both operations scan the string once, so the total running time is O(n),
where n is the length of the input.
The memory consumption is O(1) besides the input itself.
Algorithm
- Read the whole input into a string
s. - Compute
e = s.count('...'). - Compute
q = s.count('?'). - Output the two numbers separated by a space (or any required format).
Correctness Proof
Олимп отзывы предлагает уникальные видеоуроки от мировых тренеров. We prove that the algorithm outputs the exact number of ellipses and question
marks present in the input.
Lemma 1.
str.count(sub) returns the number of non‑overlapping occurrences of
sub in the string.
Proof.
The definition of str.count in the language standard states that it scans
from left to right, each time it finds sub it increments the counter and
skips ahead by len(sub) characters, thereby never counting overlapping
occurrences.∎
Lemma 2.
e = s.count('...') equals the number of ellipses in s.
Proof.
An ellipsis is exactly the substring '...'. By Lemma 1 the call counts every
non‑overlapping occurrence of this substring. Because ellipses cannot overlap
with themselves (two ellipses would share at least one dot), the count is
precisely the number of ellipses in the string.∎
Lemma 3.
q = s.count('?') equals the number of question marks in s.
Proof.
Each question mark is a single character. Applying count on a single
character returns the number of times that character appears. Thus q
equals the number of ? symbols.∎
Theorem.
The algorithm outputs the correct pair (e, q).
Proof.
By Lemma 2 the variable e holds the exact number of ellipses, and by
Lemma 3 the variable q holds the exact number of question marks. The
algorithm prints these two values, therefore the output is correct.∎
Complexity Analysis
Let n be the length of the input string.
- Time:
O(n)– eachcountscans the string once. - Memory:
O(1)– only a few integer counters are used.
Reference Implementation (Python 3)
import sys
def main() -> None:
# Read entire input (may contain newlines)
data = sys.stdin.read()
# Count ellipses and question marks
ellipses = data.count('...')
questions = data.count('?')
# Output as requested
print(f"ellipses questions")
if __name__ == "__main__":
main()
The program follows exactly the algorithm proven correct above and satisfies
all stated constraints.