#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 11. 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 22 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 11st occurrence in the text of the 11st character in the message, the 22nd occurrence in the text of the 22nd character in the message, the 33rd occurrence in the text of the 33rd 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 1313th occurrence of a character, find the6 6th, then the 33rd, then the 11st if needed)
  • Each encoded s.w.c within 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 20002000 characters and the message will be no more than 400400 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 11st occurrence of A in the text (1.1.1). The m is the 22nd character in the message so find the 22nd occurrence of m in the text. The string 1.5.3 locates that m in the 11st sentence, the 55th word, and the 33rd character in that word. The C in Computer is the 99th character in the message. There are not 99 occurrences in the text so find the 44th occurrence which is in the 22nd sentence, the 1818th word, and the 11st 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.

Attachment Download

book.zip