题目链接:http://codeforces.com/contest/533/problem/E

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
7
reading
trading
output
1
input
5
sweet
sheep
output
0
input
3
toy
try
output
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".

题解:

假设字符串为S和T,可知答案最大只能为2.

1.跳过左右两端相同的部分,直到遇到相等的字符为止。

2.只有两种情况:S的左边和T的右边为公共部分、S的右边和T的左边为公共部分。


代码如下:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e5+; int n;
char S[maxn], T[maxn]; int f(char *s1, char *s2, int i, int j)
{
while(i<j && s1[i]==s2[i+])
i++;
return i==j;
} int main()
{
scanf("%d%s%s",&n, S+,T+); int i = , j = n;
while(i<=n && S[i]==T[i]) i++;
while(j>= && S[j]==T[j]) j--; int ans = ;
ans += f(S, T, i, j);
ans += f(T, S, i, j);
cout<<ans<<endl;
}

VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串的更多相关文章

  1. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

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

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  3. VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线

    题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...

  4. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp

    题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...

  5. VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值

    E. Rooks and Rectangles Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemse ...

  6. VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)

    VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  8. VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树

    题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...

  9. codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题

    B. Photo to Remember Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...

随机推荐

  1. CompletionService 与 ExecutorService 获取任务执行结果时的区别

    CompletionService 与 ExecutorService 之间的区别 在讨论二者之间的区别之前,先交待一下背景. 看了ElasticSearch Transport模块的源码,里面充满了 ...

  2. Android动画系列 - PropertyAnim 详解

    前言:上一篇文章传统View动画与Property动画基础及比较简单对Android动画系统的基础做了介绍,本篇文章将对PropertyAnimation进行全面深入的探讨,本篇文章可以分为两大块,从 ...

  3. mac os+selenium2+chrome驱动+python3

    mac os 10.11.5 mac自带python2.7,自己下载了python3.5,pip list查看系统中的安装包,本人电脑中已经安装了pip和setuptools,若未安装,请先使用 su ...

  4. iOS 多线程技术2

    iOS 多线程技术2 NSOperation NSInvocationOperation //创建一个队列 NSOperationQueue *queue = [[NSOperationQueue a ...

  5. 百科知识 ass文件如何打开

    直接拖入视频即可播放 鼠标右键 用记事本打开 也有一些软件支持比如POPSUB(也比较方便调整时间轴) 如果你是说如何加载字幕的话 用VOBSUB是最好的... ASS是视频的字幕,和视频放在同一文件 ...

  6. 关于Adapter对数据库的查询、删除操作

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzIxMDYyMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  7. Solaris文件系统管理

    不同的操作系统使用不同类型的文件系统 1.文件(管理)系统:是用来对文件和目录进行管理.控制的数据结构的总称. Windows当中的文件系统: ntfs ,fat32 ,fat64 Solaris 当 ...

  8. opencv yuv420与Mat互转

    项目用到opencv 融合图片的功能,经过一天的调试,达到预期目标,先将如何调用opencv库实现YUV42与Mat互转记录下来. 一.下载opencv编译的库下载地址是:http://opencv. ...

  9. 【每日Scrum】第八天(4.29) TD学生助手Sprint2

    站立会议 组员 今天 签到 刘铸辉 (组长) 绩效考核 Y 刘静 测试用例书写 测试bug报告 测试详细报告 Y 解凤娇 Y 王洪叶 项目可行性报告 项目开发计划书 需求分析(已完成并发布) Y 胡宝 ...

  10. iOS移动开发周报-第17期

    lhq iOS移动开发周报-第17期 前言 欢迎国内的iOS同行或技术作者向我提交周报线索,线索可以是新闻.教程.开发工具或开源项目,将相关文章的简介和链接在微博上发布并 @唐巧_boy 即可. [摘 ...