POJ 1936 All in All 匹配, 水题 难度:0
题目
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的更多相关文章
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- POJ 3126 Prime Path bfs, 水题 难度:0
题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...
- POJ 2002 Squares 几何, 水题 难度: 0
题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后 ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- UVa 10340 - All in All 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 11039 - Building designing 贪心,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
随机推荐
- LRN(local response normalization--局部响应标准化)
LRN全称为Local Response Normalization,即局部响应归一化层,LRN函数类似DROPOUT和数据增强作为relu激励之后防止数据过拟合而提出的一种处理方法.这个函数很少使用 ...
- 虹软人脸识别 arcface2.0 安卓版本
虹软官方网站提供了 AndroidStudio 版本的arcface2.0,我花了 几天的时间整理了一个 ADT版本的源码, 是自己从 官方 2.0 android版本中转换而来的.已经测试了,可 ...
- AD绘制PCB时,贴片封装器件的焊盘间距小于10Mil,报错解决
Design->Rules->Manufacturing->Minimum Solder Mask Sliver
- C++ 实现sqilte创建数据库插入、更新、查询、删除
C/C++ Interface APIs Following are important C/C++ SQLite interface routines, which can suffice your ...
- sql server 我常用的语句
1. computed column ) persisted; 2. unique nullable create unique nonclustered index[UniqueName] on [ ...
- 第 3 章 镜像 - 015 - 调试 Dockerfile
如何 debug Dockerfile 通过 Dockerfile 构建镜像的过程 从 base 镜像运行一个容器 执行命令对容器做修改 执行类似 docker commit 的操作,生成一个新的镜像 ...
- 雷林鹏分享:查看 XML 文件
查看 XML 文件 在所有主流的浏览器中,均能够查看原始的 XML 文件. 不要指望 XML 文件会直接显示为 HTML 页面. 查看 XML 文件 - Tove Jani Reminder Don' ...
- Linux上rsync配置
一.服务器端配置1.rsyncd.conf文件说明uid = rsync #用户,用来控制用户访问模块目录的读写权限gid = rsync #组,用来控制组访问模块目录的读写权限use ...
- jquery判断设备是否是手机
//判断是否是手机 function IsMobile() { var isMobile = { Android: function () { return navigator.userAgent.m ...
- 小程序点击跳转外部链接 微信小程序提示:不支持打开非业务域名怎么办 使用web-view 配置业务域名
小程序点击跳转外部页面 1.index.wxml 添加点击事件 标签可以是小程序支持的 <!-- 邀请好友 --> <cover-image src='/img/invitat ...