# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14329 | Decoding |
|
14330 | Book Tracker |
|
Description
In this problem, you will learn how to encode and decode text using a frequency-based encoding rule. You will first create an encoding scheme based on the frequency of characters in a given text, and then use this scheme to decode a given encoded message.
Note:
- Characters should be converted to lower-case using the built-in function .lower().
- Consider spaces (' ') when counting character frequencies.
Input
- A string text (1 <= len(text) <= 10^4): represents the text to learn the encoding rule.
- A string message (1 <= len(message) <= 10^5): represents the message to be decoded.
Example Input:
Hello Jessie
1111110011011011111110011111011100101011110
Output
Decode the encoded message using the encoding scheme generated from the first line of the input text.
Encoding Rule:
- Count the frequency of each character in the text.
- Sort the characters in descending order based on their frequency. If multiple characters have the same frequency, maintain their order of occurrence.
- Encode the most frequent character with '0'.
- For each subsequent character, add a '1' to the left of the previous character's encoding.
Example Encoding:
'e': 3 times -> '0'
'l': 2 times -> '10'
's': 2 times -> '110'
'h': 1 time -> '1110'
'o': 1 time -> '11110'
' ': 1 time -> '111110'
'j': 1 time -> '1111110'
'i': 1 time -> '11111110'
Example Output:
jessie hello
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Manage the borrowing status of books in a library. The system will record the borrowing status of each book, including who borrowed the book and its return status. The library can only lend one book at a time, and if a book has already been borrowed, others will not be able to borrow it.
Input
Input multiple lines. Each line contains a borrowing or returning operation, formatted as 'time, name, borrow/return, book'. The operations are recorded in chronological order.
A 'borrow' operation indicates that the person has borrowed a book, while a 'return' operation indicates that the person has returned a book.
Output
Output the borrowing status of each book.
- If the book is currently borrowed, output the borrower's name;
- if the book is not currently borrowed, output 'In the Library'.