-->
当前位置:首页 > 题库

PROGRAMMING:Longest isomorphic prefix

Luz5年前 (2021-05-10)题库439
Isomorphic words refer to two words with the same position. "ABB" and "xingchongchong" are isomorphic words“ Abcda "and" I cheated me "are isomorphic, but" ABA "and" 666 "are not.
If the characters in the string s can be replaced by the string t according to some mapping relationship, then the two strings are isomorphic. Write a program to calculate the length of the longest isomorphic prefix (how many are isomorphic substrings) for the two input strings.
Note: 1) each character should be mapped to another character without changing the order of the characters. Different characters cannot be mapped to the same character, the same character can only be mapped to the same character, and the character can be mapped to itself. 2) Please try to control the time complexity within o (n).
###Input sample 1:
Two lines, one string for each line, with a length of less than 1000, ending with carriage return.
```in
ABB ACDE
899 8767
```
###Output sample 1:
Output an integer indicating the maximum prefix of the isomorphic word formed by two strings (the substring with the maximum number of characters in front of it is isomorphic).
In this input example, the first string: the first four are identical in pairs (repeated in the middle), the last three are not identical, the first four of the second string are identical in pairs (repeated in the middle), but the last three are identical in two:
'a' - >'8 ','b' - >'9 ',' - > ','c' - >'7 ','d' - >'6 ', but' e 'can no longer correspond to' 7 '. The longest isomorphic substrings are the first seven.
```out
seven
```
###Input sample 2:
```in
*/paper_ eight hundred and eighty-nine
+-title_ six thousand six hundred and sixty-seven
```
###Output sample 2:
The longest isomorphic substrings are the top 10“ 88 "-- >" 66 ", but" 9 "cannot correspond to" 6 ".
```out
ten
```






answer:If there is no answer, please comment