NYOJ5 Binary String Matching
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 <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的更多相关文章
- NYOJ5——Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述:Given two strings A and B, whose alph ...
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- Binary String Matching(kmp+str)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- NYOJ 5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 【ACM】Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- nyoj 题目5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- nyoj 5 Binary String Matching(string)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
随机推荐
- boxworld开发日记2019-6-8
打算做一个类似RimWorld的游戏,这里记录一下历程.首先,简单回顾一下. 2018年12月23日 场景管理,打算使用四叉树,后来发现四叉树在空间组织和内存占用方面并不占优势,之后计划使用地图分块 ...
- Authorization 头信息为空的解决方案
在 Apache配置添加SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=此次问题完美解决.
- BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...
- 向listview控件中添加数据库数据
//连接字符串 string str = "Data Source=.;Initial Catalog=mu;User ID=sa;Password=111"; //创建数据库连接 ...
- js中将html文档写入静态界面当中
1.静态界面当中: <div id="test"></div> 2.在js当中写入 $("#test").append(html文档内容 ...
- 存储过程中高性能安全式SQL拼接
不少开发人员在进行SQL拼接时头痛之极,不知道如何进行拼接操作才会更安全又不影响性能,下面我以存储过程为例与大家分享一个相对比较安全高效的方法 简介:存储过程(Stored Procedure)是在大 ...
- servU服务器连接不上问题的解决
在服务器上安装了servU64位版,建立了用户,设置了防火墙,正常启动. 但在客户端发出FTP://服务器IP 命令后,弹出输入用户名和密码的对话框,输入正确的用户名和密码后,却始终连接不上. ftp ...
- Microsoft SQL Server学习(三)
1.表:表示一个实体(客观存在的事物或抽象时间),可实现对实体的数据描述和数据操作. 2.表结构:二位平面(行.列) 3.数据类型: 类型名称 类型 整形 bit(只存储0.1) samllint i ...
- 3星|《哈佛商业评论》201708:IT项目风险之大远超你想象
老牌管理学杂志.本期干货偏少,我评3星. 以下是本期一些信息的摘抄: 1:当我们调查被关闭餐馆周边的犯罪规律时,我们发现了与关闭药房同样的现象:被关闭餐馆周围财产犯罪和车内财物偷盗犯罪行为立即出现了上 ...
- java 基础学习笔记 - 安装
1. 从www.sun.com中 下载jdk安装包 2. 执行安装包,安装jdk ,jre(Java运行环境) 3. 配置path路径 增加jdk下的bin目录. 配置完后需要重启cmd窗口,因为cm ...