nyoj——5字符串STL复习
Binary String Matching
- 描述
- Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should output 3, because the pattern A appeared at the posit
- 输入
- The first line consist only one integer N, indicates N cases follows. In each case, there are two lines, the first line gives the string A, length (A) <= 10, and the second line gives the string B, length (B) <= 1000. And it is guaranteed that B is always longer than A.
- 输出
- For each case, output a single line consist a single integer, tells how many times do B appears as a substring of A.
- 样例输入
-
3
11
1001110110
101
110010010010001
1010
110100010101011 - 样例输出
-
3
0
3#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = ; int main()
{
int t;
scanf("%d",&t);
while(t--){
string pattern;
string sym;
cin >> pattern >>sym;
int cnt = ;
while(sym.length()){
if(sym.find(pattern) > )
break;
int pos = sym.find(pattern);
sym = sym.substr(pos+);
cnt++;
}
printf("%d\n",cnt);
}
return ;
}——
nyoj——5字符串STL复习的更多相关文章
- NYOJ 113 字符串替换(C++STL解法)
字符串替换 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描写叙述 编写一个程序实现将字符串中的全部"you"替换成"we& ...
- nyoj 915 +-字符串
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和它相邻的减号交换. ...
- 洛谷 P1553 数字反转(升级版)【字符串+STL stack】
P1553 数字反转(升级版) 题目描述 给定一个数,请将该数各个位上数字反转得到一个新数. 这次与NOIp2011普及组第一题不同的是:这个数可以是小数,分数,百分数,整数.整数反转是将所有数位对调 ...
- HDOJ 1004 Let the Balloon Rise (字符串+stl)
题目: Problem Description Contest time again! How excited it is to see balloons floating around. But t ...
- C#字符串要点(复习专用)
一.字符串 通过string定义一个字符串,或者通过String类来创建对象. 通过new String() 创建有一下几种构造函数(从元数据),以此顺序创建string: // // 摘要: // ...
- PAT甲级——1112 Stucked Keyboard (字符串+stl)
此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078 1112 Stucked Keyboa ...
- nyoj 113 字符串替换 (string中替换函数replace()和查找函数find())
字符串替换 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 ...
- NYOJ 915 +-字符串【贪心】
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 Shiva得到了两个仅仅有加号和减号的字符串,字串长度同样.Shiva一次能够把一个加号和它相邻的减号交换 ...
- ES6-字符串-模板字符串(复习+学习)
昨天学习了字符串对象和字符串的表示,就是利用utf-8等不同的编码方式,还有许多的对象方法,都是处理字符串的方法,挺方便的,今天我学习了一下字符串模板,这里记录i一下学习的笔记,当然,今天学习了部分内 ...
随机推荐
- libxml2 在mingw中 xmlfree连接错误问题
libxml2 在mingw中 xmlfree连接错误问题 2013年10月02日 ⁄ 综合 ⁄ 共 1527字 ⁄ 字号 小 中 大 ⁄ 评论关闭 原地址:http://blog.csdn.net/ ...
- DOS命令安装配置Apache + MySQL + PHP 开发环境 (VC11)
一.下载 1.下载Apache 下载地址:https://www.apachelounge.com/download/VC11/ 2.下载MySQL 下载地址:http://dev.mysql.com ...
- MySql—模糊查询
实例: SQL模糊查询,使用like比较关键字,加上SQL里的通配符,请参考以下: 1.LIKE 'Mc%' 将搜索以字母 Mc 开头的所有字符串(如 McBadden). 2.LIKE '%in ...
- TypeError: Object of type 'int32' is not JSON serializable ——已解决
将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...
- JPush相关概念
JPush相关概念 连接极光服务器前提 在连接极光服务器之前需要先将APP进行注册,连接Server时需要用到下发的两个字段:AppKey:应用唯一标识.Master Secret:服务器秘钥,用于服 ...
- javaScript动画3 事件对象event onmousemove
事件对象的获取(event的获取) var event = event || window.event;(主要用这种) screenX.pageX和clientX的区别 PageY/pageX: 鼠标 ...
- 写入Csv
//定义文件输出流 FILE *f; f = fopen("a.csv" , "wb"); fprintf(f,"aaa,23,sdf\n" ...
- mybatis-3 Dynamic SQL
Dynamic SQL One of the most powerful features of MyBatis has always been its Dynamic SQL capabilitie ...
- 一个UUID生成算法的C语言实现——WIN32版本
源: 一个UUID生成算法的C语言实现——WIN32版本
- CF1137F Matches Are Not a Child's Play(LCT思维题)
题目 CF1137F 很有意思的题目 做法 直接考虑带修改的做法,上一次最大值为u,这次修改v,则最大值为v了 我们发现:\(u-v\)这条链会留到最后,序列里的其他元素相对位置不变,这条链会\(u\ ...