题目

http://poj.org/problem?id=1936

题意

多组数据,每组数据有两个字符串A,B,求A是否是B的子串。(注意是子串,也就是不必在B中连续)

思路

设置计数器cnt为当前已匹配A的长度,明显在扫描B的过程中只需要记住cnt这一个状态。

扫描B,每次与A[cnt]匹配就将计数器增加1,cnt与A的长度一致时A就是B的子串。

感想

这道题也许可以用更复杂的方法。

代码

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + ;
int nxt[maxn];
char pat[maxn];
char maz[maxn]; bool solve(){
int cnt = ;
for(int i = ;maz[i];i++){
if(maz[i] == pat[cnt])cnt++;
if(pat[cnt] == )return true;
}
return false;
} int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif // LOCAL
for(int i = ;scanf("%s%s",pat,maz)==;i++){
bool ans = solve();
if(ans){
puts("Yes");
}else{
puts("No");
}
} return ;
}

POJ 1936 All in All 匹配, 水题 难度:0的更多相关文章

  1. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  2. POJ 3126 Prime Path bfs, 水题 难度:0

    题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...

  3. POJ 2002 Squares 几何, 水题 难度: 0

    题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后 ...

  4. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  5. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  6. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  9. UVa 11039 - Building designing 贪心,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. Codeforces 801C - Voltage Keepsake

    C. Voltage Keepsake 题目链接:http://codeforces.com/problemset/problem/801/C time limit per test 2 second ...

  2. java再次学习

    1.maven配置.

  3. 第 6 章 存储 - 042 - 用 volume container 共享数据

    volume container volume container 是专门为其他容器提供 volume 的容器.它提供的卷可以是 bind mount,也可以是 docker managed volu ...

  4. nodejs初识

    提到nodejs总离不开npm,因此首先要学些和了解npm.而对于npm.nodejs的了解都来源于菜鸟教程. nodejs学习地址:http://www.runoob.com/nodejs/node ...

  5. 无法访问SVN历史记录的问题

      今天在eclipse中发现无法访问SVN的历史记录,提示条目不可读,截图如下: 用小乌龟客户端试了试也不行,截图如下: 最后解决办法是在SVN服务器上将代码仓库中conf目录下的svnserve. ...

  6. 常用标签(html+jstl+jsp)

    html:(form.input) (table.tr.td)  div (a. img.span)  h1~h6 (select.option) (br.hr.center)  (link.meta ...

  7. 【debug、info、warn、error】四者之间的区别与用法

    debug:需要在调试过程中输出的信息,但发布后是不需要的(当然发布后,也是看不到的) info:需要持续输出的信息(无论调试还是发布状态) warn:警告级别的信息(不严重) error:错误信息( ...

  8. English trip V1 - 22. My Life Teacher:Emily Key: describe talk about past 过去式

    In this lesson you will learn to talk about the past. 课上内容(Lesson) I was born in 1986. I started sch ...

  9. 使用jquery-form进行文件上传

    jquery.form.js是一个form插件,支持ajax表单提交和ajax上传. 使用时,需要在代码中添加如下: <script src="http://malsup.github ...

  10. Confluence 6 配置边栏链接

    选择图标来显示或者隐藏,页面(pages),博客页面(blogs),快捷键(shortcuts )或者导航选项(navigation options).例如,如果你希望i的这个公开主要用于博客用途,你 ...