VK 컵 2015 - 라운드 2 (비공 식 온라인 거울, Div. 1 만 해당) E.

7401 단어 online
E. Correcting Mistakes
Time Limit: 20 Sec
Memory Limit: 256 MB
제목 연결
http://codeforces.com/problemset/problem/533/E
Description
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.
Sample Input
7readingtrading
Sample Output
1
HINT
 
제목
두 문자열 모두 원 문자열 에서 알파벳 하 나 를 빼 서 얻 었 다 는 것 을 알려 드 리 겠 습 니 다.
그리고 원래 문자열 이 몇 가지 가능 한 지 물 어 볼 게 요.
문제 풀이:
분명히 최대 두 가지 가 있 는데, 우 리 는 서로 다른 위치의 중간 만 비교 하면 된다.
잘못된 관계 로
코드
 
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1050005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************

string s,t;
int n;
int main()
{
    cin>>n;
    int l=n,r=0;
    cin>>s>>t;
    for(int i=0;i<n;i++)
        if(s[i]!=t[i])
        {
            l=min(i,l);
            r=max(r,i);
        }
    int flag1=1,flag2=1;
    for(int i=l+1;i<=r;i++)
    {
        if(s[i]!=t[i-1])
            flag1=0;
        if(s[i-1]!=t[i])
            flag2=0;
    }
    cout<<flag1+flag2<<endl;
}

좋은 웹페이지 즐겨찾기