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 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/533/EDescription
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; }
相关文章推荐
- 支持不同的版本
- 码讲——Map
- 使用WinPcap和libpcap类库读写pcap文件(001)开发环境配置
- HADOOP之MAPREDUCE
- 实现有道词典功能的界面
- python BaseManager中register()的描述
- Entity Framework Code First实体关联数据加载
- Ubuntu配置Java jdk环境
- [置顶] effective java笔记(一) —— 构造器实现之builder模式
- 程序员自我修养
- 手斧Linux – 从LFS到Funtoo (117)
- 手斧Linux – 从LFS到Funtoo (116)
- 码讲——List
- Eclipse手动安装pydev
- 学习笔记:Unity战斗卡牌游戏(三)-----代码加载预设 及 Tween动画使用及播放回掉
- 阿里巴巴产品实习生2天
- 手斧Linux – 从LFS到Funtoo (115)
- 码讲——Java基本类型包装类
- 大共享永久免费云服务器评测体验
- 近期工作计划