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<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的更多相关文章
- NYOJ5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 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 ...
随机推荐
- hdoj-3371-Connect the Cities【最小生成树】
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 传奇的诞生,PHP三位创始人简介
PHP到现在为止已经诞生12年了.在这期间它经过不断改善,已经成为Web开发最重要的语言之一.PHP能有今天这样的成就,它的3位创始人(Rasmus Lerdorf.Zeev Suraski和Andi ...
- 我为什么不喜欢 CoreData
我为什么不喜欢 CoreData 我一直不喜欢 Core Data,以前不太敢明目张胆地这么表达,现在收集到越来越多相关的信息,所以给大家分享一下,我为什么不喜欢 Core Data. Core ...
- linux进程间通信消息队列:msgsnd: Invalid argument
今天写了个消息队列的小测试程序结果send端程序总是出现:msgsnd: Invalid argument,搞了半个小时也没搞明白,后来查资料发现我将(st_msg_buf.msg_type = 0; ...
- Asp.net 两个链接实现虾米音乐搜索
起因 暑假刚结束,又要回到学校写代码了,本人写代码的时候特别喜欢听歌,一直使用的是虾米音乐,出于好奇,想给自己的网站集成虾米音乐搜索功能,但是一直找不到虾米开放api,所以只能自己找办法了,之后发现一 ...
- ssh免密码访问
ssh-copy-id命令 它可以把本地主机的公钥复制到远程主机的authorized_keys文件上,ssh-copy-id命令也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh ...
- JOptionPane常用提示框
//JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); JOptionPane.sho ...
- NEU 1683: H-Index
题目描述 Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...
- gnss到底是什么呢
GNSS Global Navigation Satellite System 全球卫星导航系统:提到这个很多人会不明白GNSS倒是是个啥东西呢,和北斗,GPS, GLONASS,Galileo系统有 ...
- 利用Python3的dpkt库进行ARP扫描
背景 正在学习网络协议,用Python写起来方便点,可以快速熟悉协议本身,也给自己补充一些Python库. 偶然看到这篇文章,讲的是Python发ARP包,发现是Python2的,这里改了一下,用Py ...