# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14705 | Prez's puns |
|
14710 | Gold Ship’s quiz II |
|
Description
Symboli Rudof is trying to find new jokes to tell Air Groove, and she's asking you to inspire her! In order to do that, she's given you a list of sentences.
Your mission is to write a function called "pun" that takes in a list of string and a list of queries and print out the words at the specified index of each sentences to see if it inspires her.
Seeing you so excited to help her, she's also given you a piece of code so you can focus on your main task:
#Write your code here
(line, query) = map(int, input().split())
sentences = []
queries = []
for i in range(line):
sentences.append(input())
for i in range(query):
queries.append(tuple(map(int, input().split())))
pun(sentences, queries)
Input
The function will takes in 2 parameters:
- The first parameter is a list of strings
- The second parameter is a list of tuples (a, b):
- The first item a is the line Symboli Rudolf wants you to start from
- The second item b is the index of the word.
a >= 0, b >= 0
Output
For each tuple (a, b), print out the word at index b from sentence a to the last sentence of the list.
If the number of word in the current sentence is less than or equal to b, print out the last word of the sentence.
Print out an empty line if a is larger than the number of sentences.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
After being beaten in her own game, Gold Ship has gotten serious and made a new game to challenge Trainer-san and you again! Although, this time she added a little bit of twist to it.
The first part of the game is still the same: Given a sentence, turn the words into their lowercase version and return a dictionary containing the count of those words.
But now she's decided to add punctuations, including period (.), comma (,), and dash (-). Your additional task besides turning the words to lowercase is to remove these punctuation from the word before adding them to the dictionary.
Apart from those 3 punctuations, Gold Ship has also added the apostrophe (') with a special rule: If the word has an apostrophe, split that word into two words, with the second word containing the apostrophe at its beginning.
There could be multiple periods, commas and dashes in a word, but is guaranteed that there will be only one apostrophe per word. The punctuations could appear at any location in the word, and the words are separated by spaces.
Like before, Trainer-san has slipped you a piece of code while Gold Ship is eating to help you:
def count(inStr: str)->dict:
#Write your code here
print(sorted(count(input()).items()))
With the above code, write a function named "count" that takes a string as a parameter to complete the code and beat Gold Ship again!
Comic credit: @Setzeri
Input
Write a function take a string as a parameter.
The words in the string are separated by spaces and will contain uppercase, lowercase Latin characters, and the four punctuations: period (.), comma (,), dash (-) and apostrophe (').
Testcase limits:
- Testcase 1-2: Word contains no punctuations.
- Testcase 3-4: Word contains period, comma and dash.
- Testcase 5-6: Word contains period, comma, dash and apostrophe.
Output
And return a dictionary containing the count of lowercased version of the words.
If the word is empty, do not add them into the dictionary.