Naive Algorithm - 2 (All Occurrences)
Given two strings, P and T, where P is the pattern and T is the text in which we will search for P using a modified naive search algorithm. This algorithm compares the characters of P with each substring of T of the same length as P. The substrings of T are checked from left to right, while the characters of the pattern P are compared from right to left.
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, list all starting positions in T where the pattern P is found, separated by spaces. If the pattern does not occur in the text, output 0. On the second line, output the total number of character comparisons made. The format of input and output data should match the example provided.