Mock CCC '14 S1 - Reverse Find

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 16M

Problem type
2014 Mock CCC by Alex and Timothy

Alice has an intense, but secret crush on her friend Bob, though she's pretty sure it's not mutual. She would like to learn about his interactions with other girls that may end up being her competition. After paying for some spy training, she managed to find her way into Bob's apartment. Bob had just left to run some errands, and he happened to have left his instant messaging program open. Alice is now hanging on a rope from Bob's ceiling in front of his computer, staring directly into a chat log of all of his conversations.

She would like to bookmark the location of some keywords in the chatlog so she can look them up later when she'll have obtained the entire file. The only problem is, because she's hanging upside-down, the text is reversed and upside-down from her eyes! Luckily, she can read letters upside down, but she'll need your help bookmarking the keyword in reverse.

Specifically, given a reversed text T of no more than 1000 ASCII characters, and a keyword pattern P of no more than 100 ASCII characters, Alice needs to find the index of the first occurrence of the pattern when the string is read in reverse.

Input Specification

Line 1 of input contains the text string T.
Line 2 of input contains the pattern string P.

Output Specification

Output 1 integer—the index of the first occurrence of the pattern when the string is read in reverse. Comparisons of the text and pattern are case-sensitive. The first character of input is index 1, the second character is index 2, and so on. If the pattern cannot be reverse-found, output -1.

Sample Input 1

.boB m'I olleH :eM (MA03:21 ta tneS)

Sample Output 1


Sample Input 2

.tah eht ni tac eht :eM (MA04:21 ta tneS)

Sample Output 2



There are no comments at the moment.