| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12229 | GEC1506 Top 3 |
|
| 13174 | GEC1506-eliminate duplicated characters |
|
| 13193 | GEC1506-TopN longest words (Advanced) |
|
Description
Given a few lines of text, you need to parse it and perform the following requirements.
Hint: Please use sys.stdin instead of input() in this homework as there are multiple lines, else you will not be accepted!!!
Input
In this assignment, a few lines of text will be given as an input.
The format for each line of the text are
char,num
Hint: Not all num is Integer !!!!!!
Output
You will need to read the given input and sum the total number of each character.
You don't need to take care the numbers of the decimal for the result number.
Then, print out only the top 3 as your output results.
Note that the input and output below is just a sample test case.
Please DO NOT directly use it as your input.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a list of string elements, remove duplicated characters for each string element.
Input
The input consists of two lines:
- A list of string elements presented in the one-line text with each element separated by a special separator string
- The separator string
You need to remove the duplicated characters in each element. (Case insensitive)
For example, in the sample input,
- There are duplicated
cin the first elementEricc, it should be modified asEri. - For element
rRita, theris duplicated withR, it should be modified asita.
Note that you can use lower() in python to help you to check the characters.
text = "Ericc"
text_lower = text.lower()
print(text_lower) # "ericc"
To retrieve the character, you can use list index:
print(text_lower[0]) # "e"
Output
Print out a line of elements with duplicated characters of each element removed, where each element are connected by the above separator string in the input.
Note that there will be a new line default by python's print() function. If you are using python's print(), just ignore this line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a number N and an article with each word separated by space,
you need to return top-N longest words.
Input
The input contains two parts:
- The first line of the input is a number that indicates N numbers of top-N.
- The remaining parts of the input (multiple lines) are the content of articles with each word/token separated by SPACE.
2
hello world ! welcome to gec course for exploring world of programming
good luck in the quiz
With these inputs, you need to sort the words based on the following criteria to find the top-N words:
- Word length in descending order. You can use function
len(), e.g.len('abc') # 3. - If there are words having the same length, sort them again by the sum of the word's code using function
ord().
e.g.ord('a') # 97 - If two above values are the same for words, sort these words by their occurrence order.
Output
Print out multiple lines of distinct words in descending order.
Note that
- if N is more than the total distinct words, just print out the necessary lines of words.
e.g. if N=5, but there are only 4 words. You only need to print 4 lines of words as there is no way to print out 5 lines. - if there exists a word that occurs more than 1 time, you don't need to remove the duplicated words when you are counting. That is, the output could have duplicate words.