#P1308. [NOIP 2011 普及组] 统计单词数
[NOIP 2011 普及组] 统计单词数
Description
Most text editors have a “find word” feature that can quickly locate the position of a specific word in an article; some can also count how many times the word appears.
Now, please program to implement this feature. Specifically: given a word, output the number of times it appears in the given article and the position of its first occurrence. Note: Matching is case-insensitive, but it must be an exact match, meaning the given word must be exactly the same as an independent word in the article when case is ignored (see Sample 1). If the given word is only a part of a word in the article, it does not count as a match (see Sample 2).
Input Format
A total of lines.
The first line is a string containing only letters, representing the given word.
The second line is a string that may contain only letters and spaces, representing the given article.
Output Format
Output one line. If the given word is found in the article, output two integers separated by a single space: the number of occurrences of the word in the article and the position of its first occurrence (that is, when it first appears, the position of the word’s first letter in the article; the position starts from ). If the word does not appear in the article, output a single integer .
Note: A space counts as one character position.
To
to be or not to be is a question
2 0
to
Did the Ottoman Empire lose its power at that time
-1
Hint
Constraints
length of the word on the first line .
article length .
NOIP 2011 Junior, Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号