#P2105. ACSL 2023-2024 Senior Division Contest #2 ACSL Book
ACSL 2023-2024 Senior Division Contest #2 ACSL Book
PROBLEM DESCRIPTION
A book cipher is a method of encoding and decoding a message where the sender
and the receiver both use the same text. The sender’s message is encoded by replacing each alphanumeric character in the message to be sent with the location of that character in the text using an s.w.c format representing the number of the sentence in the text (s), the number of the word in that sentence (w), and the number of the character in that word (c), all indexed starting
with . The receiver decodes the encoded message by locating the characters in the text specified by each s.w.c string.
In this program, you will be given the text and the message to be encoded. Encode the location of each character of the message using the s.w.c format. The following rules apply:
- Any keyboard character can be included in the text or the message and all alphabetic characters are case sensitive
- A word in the text contains only alphanumeric characters and all words are separated by a
single space or any non-alphanumeric character(
s) - All sentences in the text will end with a period, question mark, or exclamation point and will be separated by exactly spaces
- Only alphanumeric characters in the message will be encoded and all other characters will remain as they are in the encoded message
- If a space occurs in the message, use an underscore (
_) for that character when encoding it - For every character in the message to be encoded, find the location of the st occurrence in the text of the st character in the message, the nd occurrence in the text of the nd character in the message, the rd occurrence in the text of the rd character in the message, etc.
- We guarantee that each character in the message will occur at least once in the text
- If there aren’t that many occurrences of a character found in the text, divide the number in half using integer division until that number of occurrences of that character is found (e.g. if there is no th occurrence of a character, find theth, then the rd, then the st if needed)
- Each encoded
s.w.cwithin a word will be separated by a single space
INPUT FORMAT
Input two strings: the text to be used and the message to be encoded. The text will be no more than characters and the message will be no more than characters.
OUTPUT FORMAT
Output the encoded message as a string of characters.
SAMPLES
EXPLANATION
SAMPLE #1
Refer to book/book1.in and book/book1.ans in the contestant directory.
SAMPLE #1 Explanation
The A is the 1st character in the message so find the st occurrence of A in the text (1.1.1).
The m is the nd character in the message so find the nd occurrence of m in the text. The
string 1.5.3 locates that m in the st sentence, the th word, and the rd character in that
word. The C in Computer is the th character in the message. There are not occurrences
in the text so find the th occurrence which is in the nd sentence, the th word, and the st
character in the word Computer (2.18.1).
There is a single space between each encoded character in each word and all non-alphanumeric
characters are included as they are in the original string except for a space which is encoded as
an underscore (_).
SAMPLE #2
Refer to book/book2.in and book/book2.ans in the contestant directory.
SAMPLE #3
Refer to book/book3.in and book/book3.ans in the contestant directory.
SAMPLE #4
Refer to book/book4.in and book/book4.ans in the contestant directory.
SAMPLE #5
Refer to book/book5.in and book/book5.ans in the contestant directory.