您的位置:首页 > 其它

VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

2015-07-01 22:56 330 查看

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.

[b]Input[/b]

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.

[b]Output[/b]

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

[b]Sample Input[/b]

7
reading
trading

[b]Sample Output[/b]

1

HINT

[b]题意
[/b]

给你俩不同的字符串,告诉你这俩字符串都已由一个原字符串减去一个字母得到了

然后问你原字符串有多少种可能

[b]题解:[/b]

显然最多两种,我们只要对比一下不同的位置的中间就好了

因为错位的关系

[b]代码[/b]

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: