VK Cup 2015
来源:互联网 发布:制作班徽用什么软件 编辑:程序博客网 时间:2024/04/23 17:09
题目链接:http://codeforces.com/contest/533/problem/E
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.
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.
Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.
7readingtrading
1
5sweetsheep
0
3toytry
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".
题解:
假设字符串为S和T,可知答案最大只能为2.
1.跳过左右两端相同的部分,直到遇到相等的字符为止。
2.只有两种情况:S的左边和T的右边为公共部分、S的右边和T的左边为公共部分。
代码如下:
#include<bits/stdc++.h>using namespace std;typedef long long LL;const double eps = 1e-6;const int INF = 2e9;const LL LNF = 9e18;const int mod = 1e9+7;const int maxn = 1e5+10;int n;char S[maxn], T[maxn];int f(char *s1, char *s2, int i, int j){ while(i<j && s1[i]==s2[i+1]) i++; return i==j;}int main(){ scanf("%d%s%s",&n, S+1,T+1); int i = 1, j = n; while(i<=n && S[i]==T[i]) i++; while(j>=1 && S[j]==T[j]) j--; int ans = 0; ans += f(S, T, i, j); ans += f(T, S, i, j); cout<<ans<<endl;}
- VK Cup 2015
- Codeforces VK Cup 2015
- VK Cup 2015
- VK Cup 2015
- [VK Cup 2015 - Round 1]简要题解
- VK Cup 2015 - Finals, online mirror
- 51Nod 1524 | Codeforces VK Cup 2015
- 【VK Cup 2012】final
- Codeforences #351 VK CUP
- VK Cup 2017
- Codeforces VK Cup 2017
- [Codeforces VK Cup 2016
- VK Cup 2017
- VK Cup 2017
- VK Cup 2017
- VK Cup 2017
- VK Cup 2015 - Qualification Round 2 C. Name Quest
- VK Cup 2015 - Qualification Round 1 B. Photo to Remember
- 正则表达式
- 深刻理解HDFS工作机制
- 正则表达式
- 数千个Android项目源码安卓游戏源码大全经典安卓项目附带源码(图片版)
- SQL语句把多个语句拼成一条
- VK Cup 2015
- css选择器权重
- Java设计模式之三种工厂模式
- Proposal Research
- jquery Multiple markers at this line问题
- 如何去做一个好的循迹小车
- 远程SQLPLUS连接失败 tns12560
- Bitmap和YUV的转换
- 公钥加密算法那些事 | RSA 与 ECC 系统对比