问题 B: Binary String Matching

时间限制: 3 Sec  内存限制: 128 MB
提交: 4  解决: 2
[提交][状态][讨论版]

题目描述

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 <cstdio>
#include <cstring> using namespace std; int main()
{
int n;
char pattern[];
char str[];
char temp[];
int cou=;
int b;
scanf("%d",&n);
for(int i=;i<n;i++){
cou=;
scanf("%s",pattern);
scanf("%s",str);
int lens=strlen(str);
int lenp=strlen(pattern);
for(int j=;j<lens;j++){
b=;
if(str[j]==pattern[]){
for(int h=;h<lenp;h++){
if(pattern[h]!=str[j+h]){
b=;
break;
}else{
continue;
}
}
if(b==){
cou++;
}
}
}
if(i==n-){
printf("%d",cou);
}else{
printf("%d\n",cou);
} } return ;
}

 

只前在自己学校oj提交可以ac,但到别的oj提交就过不了,自己学校oj的测试数据太弱!!

又重新写了一个

#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring> using namespace std; int main()
{
int n;
char ch;
int b=;
char s[];
scanf("%d",&n);
for(int i=;i<n;i++){
stack<char> st1;
scanf("%s",s);
int len=strlen(s);
st1.push(s[]);
for(int j=;j<len;j++){
b=;
if(st1.empty()){
st1.push(s[j]);
}else{
if(s[j]==')'){
if(st1.top()=='('){
st1.pop();
}else{
printf("No\n");
b=;
while(!st1.empty()){
st1.pop();
}
break;
}
}
if(s[j]==']'){
if(st1.top()=='['){
st1.pop();
}else{
printf("No\n");
b=;
while(!st1.empty()){
st1.pop();
}
break;
}
}
if(s[j]=='['||s[j]=='('){
st1.push(s[j]);
}
} } if(b!=&&st1.empty()){
printf("Yes\n");
}
if(b==&&!st1.empty()){
printf("No\n");
}
}
return ;
}
												

Binary String Matching的更多相关文章

  1. NYOJ之Binary String Matching

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

  2. ACM Binary String Matching

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

  3. Binary String Matching(kmp+str)

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

  4. NYOJ 5 Binary String Matching

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

  5. 【ACM】Binary String Matching

    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. NYOJ5——Binary String Matching

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

  8. nyoj 5 Binary String Matching(string)

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

  9. NYOJ5 Binary String Matching

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

随机推荐

  1. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  2. 密码学初级教程(六)数字签名 Digital Signature

    密码学家工具箱中的6个重要的工具: 对称密码 公钥密码 单向散列函数 消息认证码 数字签名 伪随机数生成器 提问: 有了消息认证码为什么还要有数字签名? 因为消息认证码无法防止否认.消息认证码可以识别 ...

  3. Android与Dalvik

    自学android的同事说:Android 这个妈蛋!! 当初就应该选择c++/c 来开发.现在为了效率又搞ART.简直是折腾,art在android5.0 的时候就是默认了.前段时间还在学习andr ...

  4. pipe-filter 真难找啊

    http://blog.csdn.net/absurd/article/details/4307903

  5. 正确理解JavaScript中的this关键字

    JavaScript有this关键字,this跟JavaScript的执行上下文密切相关,很多前端开发工程师至今对this关键字还是模棱两可,本文将结合代码讲解下JavaScript的this关键字. ...

  6. Xcode如何找到默认的生成路径?

    我最近刚刚入门ObjectiveC,在研习<Objective C程序设计(第6版)>一书. 今天看到有关文件和归档的章节,但是我对XCode的生成文件路径并不了解,然后,在调试代码的时候 ...

  7. Redis学习笔记五:独立功能之事务

    Redis 事务提供了一种将多个命令请求打包,然后一次性.按顺序地执行多个命令的机制,并且在事务执行期间,服务器不会中断,会将事务中的所以命令都执行完毕才去处理其他客户端的命令请求. 事务的实现 事务 ...

  8. H5图像遮罩-遁地龙卷风

    (-1)写在前面 这个idea不是我的,向这位前辈致敬.我用的是chrome49.用到的图片资源在我的百度云盘里http://yun.baidu.com/share/link?shareid=1970 ...

  9. webpack 教程 那些事儿05-多页应用

    本篇主要关于如何用webpack构建多页应用 为什么要构建多页应用呢?因为我的项目本来就是多页应用啊至于为什么要用webpack?因为我要用vue啊,嫌gulp 每次打包慢 啊 文章目录 1. 利用v ...

  10. [Asp.net MVC]Asp.net MVC5系列——添加数据

    目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...