codeforces533E
Correcting Mistakes
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 ndetermine 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 Tconsist 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 Tare 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
7
reading
trading
1
5
sweet
sheep
0
3
toy
try
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".
题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。
sol:首先把首尾两端相等的去掉,容易发现答案最大是2,
一开始睿智了,写了个XJB玩意,只判了两个位置,就会被这样的卡掉
如
aaab
baaa
于是就爆枚两种情况,一是S1的[L,R-1]等于S2的[L+1,R],还有一种就是类比一下
/*
题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,p[N],ans=,l,r,len;
char S[][N];
inline void Jud(int o)
{
int i;
for(i=l;i<r;i++)
{
if(S[o][i]!=S[o^][i+]) return;
}
ans++;
}
int main()
{
int i;
R(n);
scanf("%s%s",S[]+,S[]+);
l=; r=n;
while(S[][l]==S[][l]) l++;
while(S[][r]==S[][r]) r--;
if(l==n+&&r==)
{
Wl((n+)*); return ;
}
// cout<<l<<" "<<r<<endl;
len=r-l+;
Jud();
Jud();
Wl(ans);
return ;
}
/*
input
4
aaab
baaa
output
1
*/
codeforces533E的更多相关文章
随机推荐
- css 动画(二) transition 过渡 & animation 动画
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! translate:平移:是transform的一个属性: transform:变形:是一个静态属性,可以 ...
- shell脚本使用记录
一些比较功能需求比较简单的可以考虑使用shell脚本来写,这样可以方便快捷稳定 1. 读取文件值,根据文件值1 或 0 来开启和关闭某些程序 a. while : do done 是无限循环. b. ...
- linux gcc安装
2004年4月20日最新版本的GCC编译器3.4.0发布了.目前,GCC可以用来编译C/C++.FORTRAN.java.OBJC.ADA等语言的程序,可根据需要选择安装支持的语言.GCC 3.4.0 ...
- nginx和PHP之间的通信
如果程序员a和B在windows上开发代码,它们可以被分离到不同的服务器,因为nginx和PHP之间的通信是基于TCP fastcgi协议的我们可以在程序员的windows pc上安装nginx,使用 ...
- string leetcode-6.ZigZag
6. ZigZag Conversion 题面 The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...
- oracle排序怎样弄成1 2 3 ,而不是 1 10 100
oracle表字段设置得值不是number,而是Varchar2时排序就会出现这种问题 这个时候排序的时候需要转类型排序: order by to_number(顺序号) asc
- (六)图数据neo4j之cypher(一)
1.Cypher概述 cypher是一种声明式的图数据库查询语言,能高效的查询和更新图数据库,是依赖于模式的.所谓模式(Patterns)是就是众多节点和关系的任意复杂想法. (1)节点语法 cyph ...
- JavaFX WebView and WebEngine Tutorial教程
JavaFX WebView JavaFX WebView is a mini browser that is called as an embedded browser in JavaFX appl ...
- c# 枚举和位标志
- JLINK固件烧写
最近在使用uVision V5.14.0.0 的时候,由于我使用的Jlink是盗版的,导致软件总是退出,然后再网上找到了解决办法. 下面介绍解决办法: 参考: http://www.9mcu.com/ ...