#P5256. Code Plagiarism Detection
Code Plagiarism Detection
Code Plagiarism Detection
Given two strings representing a full code and a code snippet, determine the number of occurrences of the snippet in the full code where the snippet can match a substring of the full code by a consistent renaming of variables. In our problem, we assume that the code is represented by a string consisting of uppercase letters (A–Z) and lowercase letters (a–z). Uppercase letters represent keywords, constants, and other non-variable symbols and must match exactly. Lowercase letters represent variables, and a match is allowed if there exists a bijection (one-to-one mapping) between the variables of the snippet and those in the substring.
More formally, let S be the full code and P be the snippet. For every position i in S (0-indexed) such that the substring of S of length |P| exists, P is considered to match if there exists a bijective mapping f from the set of characters in P that are lowercase letters (variables) to the lowercase letters in the substring such that for every position j, if P[j] is uppercase then S[i+j] equals P[j], and if P[j] is lowercase then f(P[j]) equals S[i+j]. Occurrences can overlap.
Your task is to output the number of matching occurrences.
inputFormat
The input consists of two lines. The first line contains the full code string S. The second line contains the snippet string P. Both strings only contain uppercase letters (A-Z) and lowercase letters (a-z).
outputFormat
Output a single integer representing the number of occurrences of P in S that match under a consistent variable renaming.
sample
AiBjCiDECjDiFGC
AaBiCaDECiDaFGC
1