Codeforces E. Correcting Mistakes 思维

版权声明:转载请标明出处 https://blog.csdn.net/weixin_41190227/article/details/86526488

E. Correcting Mistakes

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters.

Input

The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T.

The second line contains word S.

The third line contains word T.

Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words.

Output

Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.

Examples

input

Copy

7
reading
trading

output

Copy

1

input

Copy

5
sweet
sheep

output

Copy

0

input

Copy

3
toy
try

output

Copy

2

Note

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".

题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。

思路:原串最多的可能性就就是2,只需要看两个串不同地方的区间就可以。

/*
@Author: Top_Spirit
@Language: C++
*/
#include <bits/stdc++.h>
using namespace std ;
typedef unsigned long long ull ;
typedef long long ll ;
const int Maxn = 1e5 +10 ;
const int Max = 26;
const int INF = 0x3f3f3f3f ;

string s1, s2 ;

int main (){
    int n ;
    cin >> n >> s1 >> s2 ;
    int l = INF, r = -INF ;
    for (int i = 0; i < n; i++){
        if (s1[i] != s2[i]){
            l = min(l, i) ;
            r = max(r, i) ;
        }
    }
    int ans1 = 1 , ans2 = 1 ;
    for (int i = l + 1; i <= r; i++){
        if (s1[i] != s2[i - 1]) ans1 = 0 ;
        if (s1[i - 1] != s2[i]) ans2 = 0 ;
    }
    cout << ans1 + ans2 << endl ;
    return 0 ;
}

纠正一个笨蛋,他会讨厌你

纠正一个聪明的人,他会感激你

猜你喜欢

转载自blog.csdn.net/weixin_41190227/article/details/86526488