Binary String Matching

时间限制:3000 ms  |  内存限制:65535 KB
难度: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

思路:这个只是简单匹配,要是有时间限制的话,可以用KMP算法处理

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio> using namespace std; int main(){ int n;
cin>>n;
string a,b;
while (n--)
{
cin>>a>>b;
int count = ;
for (int i = ; i < b.length(); i++)
{
int k = i;
int j = ;
while(k<b.length() && j<a.length()){ if (j==a.length()- && b[k]==a[j])
{
count++;
}
if (b[k]==a[j])
{
k++;j++;
}else{
break;
} } }
cout<<count<<endl;
} return ;
}

【ACM】Binary String Matching的更多相关文章

  1. ACM Binary String Matching

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

  2. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

  3. NYOJ之Binary String Matching

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

  4. 【故障处理】ORA-28040: No matching authentication protocol

    [故障处理]ORA-28040: No matching authentication protocol 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者 ...

  5. Binary String Matching

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

  6. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  7. Binary String Matching(kmp+str)

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

  8. NYOJ 5 Binary String Matching

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

  9. 【CF662C】Binary Table(FWT)

    [CF662C]Binary Table(FWT) 题面 洛谷 CF 翻译: 有一个\(n*m\)的表格(\(n<=20,m<=10^5\)), 每个表格里面有一个\(0/1\), 每次可 ...

随机推荐

  1. bzoj 4407 于神之怒加强版 —— 反演+筛积性函数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4407 推导如这里:https://www.cnblogs.com/clrs97/p/5191 ...

  2. iPhone白苹果怎么办?白苹果各种解决办法方法

    iPhone白苹果怎么办?白苹果各种解决办法方法 日期:2014-07-16 来源:爱思助手 浏览次数:60962 越狱后大家也疯狂的装入各种插件,由于一些插件会产生冲突,造成白苹果现象,无法进入手机 ...

  3. freeMaker的工具类

    package com.ek.util; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import jav ...

  4. js检测对象属性

    In:(检测自身及原型属性) var o={x:1}; "x" in o; //true,自有属性存在 "y" in o; //false "toSt ...

  5. windows统计端口连接数

    netstat -na -p tcp| findstr 80 | find /C "ESTABLISH" netstat -an -p tcp | find "127.0 ...

  6. css菜鸟之HTML 中块级元素设置 height:100% 的实现

    HTML 中块级元素设置 height:100% 的实现 当你设置一个页面元素的高度(height)为100%时,期望这样元素能撑满整个浏览器窗口的高度,但大多数情况下,这样的做法没有任何效果. 为什 ...

  7. webrower + CEF

    理解WebKit和Chromium: Content API和CEF3 标签:               apiAPIAPibrowserchromeChromehtml5HTML5Html5web ...

  8. AES算法的c++实现

    该模板无填充操作. 1.AES.h #include<cstdio> #include<cstring> #include<algorithm> #include& ...

  9. [hdu4960]Another OCD Patient(区间dp)

    题意:给出n个数,把这n个数合成一个对称的集合.每个数只能合并一次. 解题关键:区间dp,dp[l][r]表示l-r区间内满足条件的最大值.vi是大于0的,所以可以直接双指针确定. 转移方程:$dp[ ...

  10. 《精通Spring4.X企业应用开发实战》读后感第五章(FactoryBean)