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 ...
随机推荐
- linux c/c++ 获取文件大小
linux c/c++ 获取文件大小 #include <sys/stat.h> int FileSize(const char* fname) { struct stat statbuf ...
- 修改Anaconda中的Jupyter Notebook默认工作路径
这二天,安装了anaconda想更改jupyter的工作路径,在网上找了一下 方式1. 打开Windows的cmd,在cmd中输入jupyter notebook --generate-config如 ...
- MYSQL常用函数(类型转化函数)
为了进行数据类型转化,MySQL提供了CAST()函数,它可以把一个值转化为指定的数据类型.类型有:BINARY,CHAR,DATE,TIME,DATETIME,SIGNED,UNSIGNED 示例: ...
- WebSocket前后台交互
其实对于前后台交互有很多种方法(只列举我知道的,嘻嘻): 1:from 表单: 使用场景——小信息量提交给后台 2:ajax(跨域的话用jsonp): 可以进行多量的前后台信心传递: 但实时性不高,不 ...
- sql server auto increment - trace flag 272
从 sql 2012 开始, 微软为了让 insert 时 auto increment 快一些,做了一个 cache 的机制. 这个机制虽然好,但是也有麻烦的情况,如果你的 sql 突然 resta ...
- 20165327 2017-2018-2 《Java程序设计》第2周学习总结
20165327 2017-2018-2 <Java程序设计>第2周学习总结 内容:教材第2.3章 内容小结: (一)标识符由字母.下划线.美元符号和数字组成, 并且第一个字符不能是数字字 ...
- Python的特殊成员
Python 用下划线作为变量前缀和后缀指定特殊变量 _xxx 不能用’from module import *’导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...
- 学习Py——自己模拟写的一个Range功能
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" # function: Modeled range ...
- HTML页面加载完毕后运行的js
Js方法:<script type=”text/javascript”> window.onload=function (){ var userName=”xiaoming”; alert ...
- 安卓——implements——OnClickListener
//实现底部的按钮激活监听 设置不同src class click implements OnClickListener{ @Override public void onClick(View v) ...