Naive Algorithm – 2 (First Occurrence)
Given two strings, P and T: P is the pattern, and T is the text where we will search for P using a modified version of the naive search algorithm. In this algorithm, substrings of T are traversed from left to right, while the characters of the strings are compared from right to left. During each character comparison, the character from P being compared must be printed. After completing the search, print the starting position of P in T, or print 0 if P does not appear in T.
Input Data
The first line of the input contains the pattern P (1 ≤ size(P) ≤ 100), and the second line contains the text T (1 ≤ size(T) ≤ 100).
Output Data
On the first line of the output, print the characters of the pattern P that are compared. On the second line, print the position of the first occurrence of the pattern P in the text T, or 0 if it does not occur. Format the input and output data according to the example.