토큰과 매개변수로 이루어진 패턴 P와 텍스트 T가 주어질 때, 매개변수의 일대일 재명명으로 P와 p-일치하는 T의 모든 부분 문자열 위치를 구한다.
어려움8문자열 매칭문자열해시맵슬라이딩 윈도우아직 제출이 없습니다메모리 제한16 MBAn important problem of software maintenance is to track down duplication in a large software system. One would like to find not only exact matches between sections of code, but parameterized matches, where a parameterized match between two sections of code means that one section can be transformed into the other by replacing the parameter names (e.g., identifiers and constants) of one section by the parameter names of the other via a one-to-one (bijective) function.
Let Σ and Π be two alphabets: Σ is the upper case English alphabet and Π is the lower case English alphabet. Each symbol in Σ represents a token and each symbol in Π represents a parameter.
A string can consist of any combinations of tokens and parameters from Σ and Π. Two strings A and B are said to p-match if and only if
A token represents a part of the program that cannot be changed, whereas a parameter represents a program's variable, which can be renamed as long as all occurrences of the variable are renamed consistently. Thus if A and B p-match, then the variable names in A could be changed to the corresponding variable names in B, making the two programs identical. If these two problems were part of a larger program, then they could both be replaced by a call to a single subroutine.
Given a text T and a pattern P, each a string over Σ and Π, find all substrings of T that p-match P.
The first line of the input contains the string P followed by the second line containing the string T.
The output must contain on the first line the number of substrings of T that p-match P. On the second line the offsets of those substrings are to be printed separated by a space (by convention, the prefixes of T have offset 1).
The pattern XYabCaCXZddbW p-matchs the 2-offset text substring XYdxCdCXZccxW but does not pmatch the 1-offset text substring xXYdxCdCXZccx.
Notice that when the p-match occurs, the following one-to-one (bijective) function f is used:
a) = db) = xd) = c