#P4754. Correcting Mistakes
Correcting Mistakes
Correcting Mistakes
题面翻译
给你两个长度为 的字符串 ,问是否有一个字符串 使得 均能通过 删除一个字符得到。输出有多少个 能满足题意。
题目描述
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word.
Implement a program that can, given two distinct words and of the same length determine how many words of length are there with such property that you can transform into both , and by deleting exactly one character. Words and consist of lowercase English letters. Word also should consist of lowercase English letters.
输入格式
The first line contains integer ( ) — the length of words and .
The second line contains word .
The third line contains word .
Words and consist of lowercase English letters. It is guaranteed that and are distinct words.
输出格式
Print a single integer — the number of distinct words that can be transformed to and due to a typo.
样例 #1
样例输入 #1
7
reading
trading
样例输出 #1
1
样例 #2
样例输入 #2
5
sweet
sheep
样例输出 #2
0
样例 #3
样例输入 #3
3
toy
try
样例输出 #3
2
提示
In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).
In the second sample test the two given words couldn't be obtained from the same word by removing one letter.
In the third sample test the two given words could be obtained from either word "tory" or word "troy".