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
#include<iostream>//我用模式匹配算子串出现的次数
#include<string>
using namespace std; int Match(string pat,string sat)
{
int count=;
int i=;
int m=pat.length(),n=sat.length();
while(i<=(n-m))
{
int j=;
while((sat[i]==pat[j])&&(j<pat.length()))
{
i++;
j++; }
if(j==pat.length())
{
count++;
}
i=i-j+;
} return count;
}
int main()
{ int num;
cin>>num;
string pat,sat;
while(num--)
{
int p=,s=;
int count;
cin>>pat;
cin>>sat; count=Match(pat,sat);
cout<<count<<endl;
} return ;
}

NYOJ5——Binary String Matching的更多相关文章

  1. NYOJ5 Binary String Matching

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

  2. Binary String Matching

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

  3. NYOJ之Binary String Matching

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

  4. ACM Binary String Matching

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

  5. Binary String Matching(kmp+str)

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

  6. NYOJ 5 Binary String Matching

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

  7. 【ACM】Binary String Matching

    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. nyoj 5 Binary String Matching(string)

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

随机推荐

  1. 应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为

    应用程序中的server错误,没有名称为"ServiceBehavior"的服务行为         今天在阅读"创建和使用Web服务"的相关内容,在浏览器中查 ...

  2. 【Linux学习笔记】栈与函数调用惯例

    栈与函数调用惯例(又称调用约定)— 基础篇 记得一年半前参加百度的校招面试时,被问到函数调用惯例的问题.当时只是懂个大概,比如常见函数调用约定类型及对应的参数入栈顺序等.最近看书过程中,重新回顾了这些 ...

  3. BUPT复试专题—串查找(?)

    https://www.nowcoder.com/practice/a988eda518f242c29009f8620f654ede?tpId=67&tqId=29642&rp=0&a ...

  4. 创建git仓库及简单操作命令

    1.把已有的项目代码纳入git管理 $ cd projectdir  #projectdir项目代码所在的文件夹 $ git init 2.新建的项目直接使用git管理 $ cd dir  #dir ...

  5. 关于android 使用bitmap的OOM心得和解决方式

    android开发,从2010年開始学习到如今的独立完毕一个app,这漫长的四年,已经经历了非常多次bug的折磨.无数次的加班训练.然而,自以为自己已经比較了解android了,却近期在一个项目上.由 ...

  6. Intel Edision —— 开发环境选择一贴通

    前言 原创文章,转载引用务必注明链接.如有疏漏,欢迎斧正. 使用Intel开发板设置工具配置好之后,会自动跳转到集成开发环境(integrated development environment,ID ...

  7. 基于社交网络的情绪化分析IV

    基于社交网络的情绪化分析IV By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明出处,谢谢. 前面进行了微博数据的抓取,简单的处理,类似度分析.后面两篇进行学 ...

  8. XUtils BitmapUtils 改造以加入drawable支持

    === XUtilsBitmapUtils 改造以加入drawable支持 === # XUtils 简单介绍 XUtils 是一套少有的早期国产安卓框架, 其源于AFinal, 文件夹结构也与之相似 ...

  9. PHP接收参数的几种方式

    PHP5在默认的情况下接收参数是需要使用 $_GET['value']; $_POST['value']; 还可以在PHP.ini 文件中的  将register_globals = Off  改re ...

  10. vim字符串替换命令

    呜呜老是忘. 这里记录一下,仅仅记录当中日经常使用的最多的命令. :%s/str1/str2/g   替换每一行中全部str1为str2 经常使用! :s/str1/str2/g 替换当前行全部str ...