题目

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. 微信小程序不可操作dom节点

    //根据历史记录快速搜索 fastSearch:function(e){ console.log(e.currentTarget.id) wx.navigateTo({ url: '../search ...

  2. 第 6 章 存储 - 043 - data-packed volume container

    data-packed volume container 将数据打包到镜像中,然后通过 docker managed volume 共享 1.先用Dockerfile 构建镜像 ADD 将静态文件添加 ...

  3. MATLAB 编辑器和程序调试

  4. Oracle:如何创建一个只有查看权限的用户

    因为工作中测试环境和开发环境是分开的,所以开发有时处理bug时需要连接测试数据库,这样出现一个问题是有些开发会为了验证某些问题任意改动数据库的表和字段,对测试库造成污染.为了能够让开发连接测试环境,同 ...

  5. 输出图片格式BARTENDER

    try {                BarTender.Application btApp = new BarTender.Application();                BarTe ...

  6. 安卓四大组件之Sevice组件的简单使用 --Android基础

    1.本例实现了简单的Service(服务)的创建.启动和停止,点击“启动SERVICE”页面会显示“服务被创建”,接着是“服务被启动”.点击“停止SERVICE”页面提示“服务被停止”.太过基础,直接 ...

  7. p1218 Superprime Rib

    深搜,添加数字后如果仍为质数,继续递归. #include <iostream> #include <cstdio> #include <cmath> #inclu ...

  8. MySQL表类型和存储引擎

    一.基本介绍 从事务安全性的角度,可以把存储引擎分为两大类: 事务安全: BDB和innodb; 事务非安全性: myisam 和 memory 二.存储引擎的比较图 看你的mysql当前默认的存储引 ...

  9. Python基础之文件的基本操作

    概述:文件的基本操作1.open 打开文件 f = open("xxx",mode="r",encoding="utf-8") #常用形式 ...

  10. git clone项目

    1. 生成公钥和私钥 ssh-keygen 2. 将公钥添加到github或者gitlab上,一般github或者gitlab允许添加多个公钥,可能是考虑到用户使用不同的机器了吧,还是很贴心的. 3. ...