题目链接: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的左边为公共部分。


代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const double eps = 1e-6;
 5 const int INF = 2e9;
 6 const LL LNF = 9e18;
 7 const int mod = 1e9+7;
 8 const int maxn = 1e5+10;
 9
10 int n;
11 char S[maxn], T[maxn];
12
13 int f(char *s1, char *s2, int i, int j)
14 {
15     while(i<j && s1[i]==s2[i+1])
16         i++;
17     return i==j;
18 }
19
20 int main()
21 {
22     scanf("%d%s%s",&n, S+1,T+1);
23
24     int i = 1, j = n;
25     while(i<=n && S[i]==T[i]) i++;
26     while(j>=1 && S[j]==T[j]) j--;
27
28     int ans = 0;
29     ans += f(S, T, i, j);
30     ans += f(T, S, i, j);
31     cout<<ans<<endl;
32 }

View Code

转载于:https://www.cnblogs.com/DOLFAMINGO/p/7538667.html

VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串相关推荐

  1. VK Cup 2015 - Qualification Round 1 A. Reposts(树)

    传送门 Description One day Polycarp published a funny picture in a social network making a poll about t ...

  2. VK Cup 2017 - Round 1

    传送门 A. Bear and Friendship Condition(思维or完全图判定) •题意 给你n个人,m个朋友关系 朋友是会传递的,若A B是朋友,A C是朋友,则必须有B C的朋友关系 ...

  3. Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)

    原题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意: ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题...

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  5. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3)

    点击打开A题链接 #include<bits/stdc++.h> using namespace std; const int MAX = 105; int n,s;int h[MAX], ...

  6. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  7. VK Cup 2017 - Round 2

    FallDream打的AB都FFT了,只剩一个我打的C,没进前一百,之后看看马拉松复活赛有没机会呗. A. Voltage Keepsake 题目大意:n个东西,每个东西一开始有bi能源,每秒消耗ai ...

  8. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)B. Primal Sport

    Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

最新文章

  1. java做个简单的登录界面_java一个简单的登录界面制作
  2. 2013 全国高校计算机等级考试(广西考区)一级笔试试题,全国高校计算机等级考试(广西考区)一级笔试试题卷.PDF...
  3. 备忘录(scanf和continue)
  4. CF16A Flag
  5. 汇报时,如何让老板快速抓住重点?—— 黄金三步法
  6. 17.1 Replication Configuration 复制:
  7. js判断对象是否为空或对象的属性是否为空
  8. mysql排序同值排名一致
  9. MAC地址批量生成器
  10. 数字图像处理 冈萨雷斯 (第四版) 比特平面分层,图像重建
  11. 中小学python教材电子版_【python爬虫】中小学人教版教材下载实践
  12. 浅谈 光学字符识别(OCR识别)技术的前世今生...
  13. JSP介绍及视频教程
  14. pad平板性能测试软件,苹果iPad 2020款评测,最便宜的iPad,性能碾压安卓?
  15. 为什么我卸载了微博?
  16. 示波器电流探头传播延迟的测量
  17. 转载:汽车上的控制器简介
  18. 微信小程序中 scroll-view滚动条始终在最底部
  19. B端硬件产品需求评审
  20. 目前有哪些好用的测试管理工具?

热门文章

  1. win7系统封装小记
  2. ROS/51单片机/机器人控制器实验报告册
  3. 天太机器人吴志诚_配天机器人CEO索利洋:用原创打造中国机器持久生命力
  4. C8051F环境搭建
  5. 英文版 耶稣爱我 Jesus Loves me 童声
  6. CAN总线转光纤/CAN光端机在海湾消防报警主机联网中应用
  7. 实验习题 Java 1.1
  8. 在ARM开发板上实现LCD+USB键盘
  9. 全国计算机信息高新技术考试办公软件应用模块技师级,全国计算机信息高新技术考试办公软件应用模块高级操作员级考试考....
  10. 无需编程的BEAM昆虫积木机器人~适合小孩子的益智DIY小制作