5-Binary String Matching

内存限制:64MB 时间限制:3000ms 特判: No
通过数:232 提交数:458 难度:3

题目描述:

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 可以用find。
注意用getchar()。。。。。。。
C++代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int T;
scanf("%d",&T);
getchar(); //必须加上
while(T--){
string s1;
string s2;
getline(cin,s1);
getline(cin,s2);
int ans = s2.find(s1,);
int num = ;
while(ans >= ){
num++;
ans = s2.find(s1,ans+);
}
printf("%d\n",num);
}
return ;
}

(find) nyoj5-Binary String Matching的更多相关文章

  1. NYOJ5——Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3  描述:Given two strings A and B, whose alph ...

  2. NYOJ5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  3. Binary String Matching

    问题 B: Binary String Matching 时间限制: 3 Sec  内存限制: 128 MB提交: 4  解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...

  4. NYOJ之Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述     Given two strings A and B, whose a ...

  5. ACM Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  6. Binary String Matching(kmp+str)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  7. NYOJ 5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  8. 【ACM】Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  9. nyoj 题目5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  10. nyoj 5 Binary String Matching(string)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

随机推荐

  1. Lodop中特殊符号¥打印设计和预览不同

    Lodop中¥符号样式改变问题 Lodop中对超文本样式的解析,虽然说是按照调用的本机ie引擎,但是调用的ie版本可能不同,导致在ie下是一种样式,预览又是另一种样式.可能是有些样式没有具体设置,走的 ...

  2. change safari user agent

    defaults write com.apple.safari customuseragent '"mozilla/5.0 (iphone; cpu iphone os 8_1 like m ...

  3. Jenkins+PowerShell持续集成环境搭建(四)常用PowerShell命令

    0. 修改执行策略 Jenkins执行PowerShell脚本,需要修改其执行策略.以管理员身份运行PowerShell,执行以下脚本: Set-ExecutionPolicy Unrestricte ...

  4. Paint it really, really dark gray CodeForces - 717E

    Paint it really, really dark gray CodeForces - 717E 题意 有一棵树 每个结点是粉色或黑色 每经过一个结点 就改变他的颜色 从1开始遍历 打印出一条路 ...

  5. c++ string类型的定义及方法

    1.c++ 有两种风格的字符串形式  c风格字符串  定义及初始化  char a[]={'h','e','l','l','o','\0'}  或者  char a[]="hello&quo ...

  6. luogu2258

    题面 sol:先爆搜搜出r行,再在那r行中选c列DP得到最优解 我太菜了,这种题都做了好久,还需锻炼码力啊qwq #include <cstdio> #include <cstrin ...

  7. gym-101350D

    题意:给你一个数组,你每次可以是其中一个数减一,数组其他元素加一,问是否能够相等,这个数组的所有元素. 解题思路:将数组从小到大排序,只要后一项减去当前项的值是奇数就行了. 代码: #include& ...

  8. Django的View(视图)

    Django的View(视图) 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应可以是一张网页的HTML内容,一个重定向,一个404错误, ...

  9. BZOJ4128Matrix——hash+矩阵乘法+BSGS

    题目描述 给定矩阵A,B和模数p,求最小的x满足 A^x = B (mod p) 输入 第一行两个整数n和p,表示矩阵的阶和模数,接下来一个n * n的矩阵A.接下来一个n * n的矩阵B 输出 输出 ...

  10. BZOJ2219数论之神——BSGS+中国剩余定理+原根与指标+欧拉定理+exgcd

    题目描述 在ACM_DIY群中,有一位叫做“傻崽”的同学由于在数论方面造诣很高,被称为数轮之神!对于任何数论问题,他都能瞬间秒杀!一天他在群里面问了一个神题: 对于给定的3个非负整数 A,B,K 求出 ...