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 <cstring>
using namespace std; int main()
{
int T;
char a[];
char b[];
int i;
int j;
int count;
int temp;
int a_length;
int b_length; cin >> T;
while (T--)
{
cin >> a >> b; count = ;
a_length = strlen(a);
b_length = strlen(b);
for (i = ;i < b_length-a_length+;i++)
{
temp = i;
for (j = ;j < a_length;temp++,j++)
{
if (b[temp] != a[j])
{
break;
}
} if (j >= a_length)
{
count++;
}
}
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 alph ...

  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. 数组去重----es6&es5&数组对象去重

    es6方法: 普通数组: 1.使用Array.from(new Set(arr)); /* * @param oldArr 带有重复项的旧数组 * @param newArr 去除重复项之后的新数组 ...

  2. DHTML_____window对象的事件

    <html> <head> <meta charset="utf-8"> <title>window对象事件</title&g ...

  3. 全面学习ORACLE Scheduler特性(9)创建Chains

    五.使用Chains 今天要来认识一位新同学:CHAIN(注意不要敲成CHINA).CHAIN可以被视做一组Programs的复合,举个简单的例子:运行PROGRAM:A以及PROGRAM:B,如果成 ...

  4. 238 Product of Array Except Self 除自身以外数组的乘积

    一个长度为 n 的整形数组nums,其中 n > 1,返回一个数组 output ,其中 output[i] 等于nums中除nums[i]以外所有元素的乘积.不用除法 且在O(n)内解决这个问 ...

  5. js中原型和原型链

    1.原型: 在JavaScript 中,对象被表现为prototype . 原型其实一直存在于我们接触过的任何一个对象. 2. Tip:在函数对象中也存在__proto__属性,但是查看函数对象的原型 ...

  6. Jsp页面,结果集分页和sql(top)分页的性能对比

    jsp页面两种分页模式: 第一种: 结果集分页,主要代码见下面: ResultSet rs=stmt.executeQuery(sql); ResultSetMetaData md=rs.getMet ...

  7. Assembly之instruction之Status register

    The status register (SR/R2), used as a source or destination register, can be used in the register m ...

  8. python学习笔记(6)——for...in &while

    for x in ...循环就是把每个元素代入变量x,然后执行缩进块的语句. 注意:python中的格式也起到语法规则的作用,缩进块就是一个例 求和问题,比较异同 1/sum= ,,,,,,,,,]: ...

  9. android framework 图解分享

    android framework 图解 个人网站:http://www.51pansou.com Android视频下载:Android视频 Android源码下载:Android源码 Androi ...

  10. position的简单用法实例 ----- 方框里图片放对应的角标

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...