题目描述

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.
The first N characters equal to the string s.
The last N characters equal to the string t.
Find the length of the shortest string that satisfies the conditions.

Constraints
1≤N≤100
The lengths of s and t are both N.
s and t consist of lowercase English letters.

输入

The input is given from Standard Input in the following format:

N
s
t

输出

Print the length of the shortest string that satisfies the conditions.

样例输入

3
abc
cde

样例输出

5

提示

The shortest string is 'abcde'.

#include <bits/stdc++.h>

using namespace std;
int main(){
ios::sync_with_stdio(false);
int len;
string a,b;
cin>>len;
cin>>a>>b;
int i,j,sum=len*,ans=len*;
i=len-,j=len-;
while(j>=&&i>=)
{
if(a[i]==b[j]){
i--;
j--;
sum--;
}
else if(a[i]!=b[j]&&i!=len-){
i=len-;
sum=len*;
}
else if(a[i]!=b[j]&&i==len-){
j--;
sum=len*;
}
}
i=len-,j=len-;
swap(a,b);
while(j>=&&i>=)
{
if(a[i]==b[j]){
i--;
j--;
ans--;
}
else if(a[i]!=b[j]&&i!=len-){
i=len-;
ans=len*;
}
else if(a[i]!=b[j]&&i==len-){
j--;
ans=len*;
}
}
cout<<min(ans,sum)<<endl;
}

这道题刚开始就WA了一大片

这个不能天真的以为b接在a后面

还有天天吃小白菜的代码真的太乱了

今天亲自敲了一下

Prefix and Suffix的更多相关文章

  1. [LeetCode] Prefix and Suffix Search 前后缀搜索

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  2. [Swift]LeetCode745. 前缀和后缀搜索 | Prefix and Suffix Search

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  3. 745. Prefix and Suffix Search 查找最大index的单词

    [抄题]: Given many words, words[i] has weight i. Design a class WordFilter that supports one function, ...

  4. Prefix and Suffix Search

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  5. 【leetcode】745. Prefix and Suffix Search

    题目如下: Given many words, words[i] has weight i. Design a class WordFilter that supports one function, ...

  6. <trim>: prefix+prefixOverrides+suffix+suffixOverrides

    <trim prefix="where" prefixOverrides="where" suffixOverrides="and"& ...

  7. SpringMVC-组件分析之视图解析器(prefix,suffix)

    SpringMVC的默认组件都是在DispatcherServlet.properties配置文件中配置的: spring-webmvc->org/springframewrok/web/ser ...

  8. mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>的含义

    转自:http://blog.csdn.net/qq_33054511/article/details/70490046   <trim prefix="" suffix=& ...

  9. mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>

    1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=&quo ...

随机推荐

  1. SpringMVC的配置文件说明

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. bitcoin-cli

    == Blockchain ==getbestblockhashgetblock "blockhash" ( verbosity ) getblockchaininfogetblo ...

  3. .NET微信开发 配置微信公众号基本配置的几种方法

    自己最近搞了公众号,记录一下. 目的就是为了在微信公众号里启用服务器配置. 微信文档 其实微信文档已经写得很清楚了,也很简单.(微信的目的就是它发送一个get请求,希望我们能接受一下,然后给微信回个数 ...

  4. Swagger注解及参数细节的正确书写。

    今天新开了一个api文件,结果怎么搞也在swagger里显示不出来,浪费半天后,去问老员工了. 一般有俩原因, 1.idea缓存,重启idea即可. 2.注解和参数上的修饰有问题,或者请求method ...

  5. PAT A1005-1008

    A 1005 Spell It Right (20 point(s)) 25分的题目,比较简单,注意N的范围,用字符串处理即可. #include <iostream> #include ...

  6. Hadoop的常用指令

    -help:查看帮助 hadoop fs -help rm -rm [-f] [-r|-R] [-skipTrash] <src> ... : Delete all files that ...

  7. Linux(CENTOS7) Redis安装

    1.下载redis         在disk目录下,输入以下命令进行下载: wget http://download.redis.io/releases/redis-2.8.3.tar.gz 2.解 ...

  8. thinkcmf2.2 火狐浏览器图片上传以及谷歌图片上传打开稍慢

    对目录中 admin/themes/simplebootx/asset/plupload.html 文件 进行更改如下图:

  9. JS变量、作用域及内存

    1.动态属性var box = new Object();box.name = 'lee';alert(box.name); var box = 'lee';box.age = '28';alert( ...

  10. 题解 P6004 【[USACO20JAN]Wormhole Sort S】

    这题真的是非常标准的模板题啊 看到连最少的边,第一时间会想到 \(kruskal\) .这道题的难点其实就一个:你要注意到连边权最大的边使整个图联通 为什么:题意是第i个点想走到 \(pos[i]\) ...