| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12269 | GEC1506 Encoding |
|
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!!!
If there are some character have same frequency, please order them according to the order of occurence.
- For example: In sample input, 'l' and 'e' have same frequency (2). And 'e' appears beofre 'l' in the text. So in your list, 'e' should also appear before 'l'.
Input
In this assignment, a few lines of text will be given as an input.
Output
You will need to read the given input and count the frequency of each character appear in the sentences. (You don't need to encode the space character ' '. )
Then, sort (stable sort) the characters based on the frequency of the word. (from max to min)
After sorting, you will now have a list starting from the most frequent character. You need to encode the characters.
Example Input:
hello john
how are youAfter counting and sorting,
You will get
'o' for 4 times
'h' for 3 times
'e' for 2 times
...
Encode:
The order of the characters will encode to alphabet according to alphabetical order (a-z).
For example,
'o' is the most frequent character, so we encode it to 'a'.
'h' is the second frequent character, so we encode it to 'b'.
followed by this rule, we can encode all our characters.
Note that the input and output below is just a sample test case.
Please DO NOT directly use it as your input.