Shakespeare 1


Submit solution

Points: 2
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Python3

In this problem, you are expected to read information from shakespeare-hamlet.txt (Click to download), and perform basic occurrence count.

Assume each line is a separate sentence, you are to count in how many lines did a single word show up. You will have to include both uppercase and lowercase occurrences.

Hint: here's a list of special symbols you will need to handle:

[](){},.?!'":;-

Important note! Upon seeing these symbols, you should SPLIT the string.

Input Specification

The input will start with the content of shakespeare-hamlet.txt, followed by a line of separators

--------

After the separators come the actual test cases.

The first line will contain 1 integers \(n\) (\(1 \le n \le 100\)), which is the total number of queries.

The next \(n\) lines will each contain a single word in lowercase.

Output Specification

Output \(n\) lines, each containing one integer, which is the number of lines a word has shown up in.

Sample Input 1

[content of shakespeare-hamlet.txt]
--------
5
frailty
cunning
stowed
herald
skin

Sample Output 1

1
4
1
1
1

Special Note:

Here's some python instructions: To test your code, you can read the hamlet text from the file instead of stdin:

raw_hamlet = []
with open("shakespeare-hamlet.txt", "r") as input_file:
    for line in input_file:
        raw_hamlet.append(line)

and when submitting to the OJ, replace the code above with reading from stdin:

raw_hamlet = [input() + "\n"]
while raw_hamlet[-1] != "--------\n":
    raw_hamlet.append(input() + "\n")

Careful, when reading from stdin, the newline symbols will not appear in your str, this is different from using file operations. Please make sure you process the raw input for special symbols as well.


Comments


  • 0
    jetic  commented on Nov. 3, 2021, 1:14 a.m.

    Here's some python instructions: To test your code, you can read the hamlet text from the file instead of stdin:

    raw_hamlet = []
    with open("shakespeare-hamlet.txt", "r") as input_file:
        for line in input_file:
            raw_hamlet.append(line)

    and when submitting to the OJ, replace the code above with reading from stdin:

    raw_hamlet = [input() + "\n"]
    while raw_hamlet[-1] != "--------\n":
        raw_hamlet.append(input() + "\n")

    Careful, when reading from stdin, the newline symbols will not appear in your str, this is different from using file operations. Please make sure you process the raw input for special symbols as well.