Binary String Matching
问题 B: Binary String Matching
时间限制: 3 Sec 内存限制: 128 MB
提交: 4 解决: 2
[提交][状态][讨论版]
题目描述
输入
输出
样例输入
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的更多相关文章
- 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 ...
- NYOJ5——Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述:Given two strings A and B, whose alph ...
- nyoj 5 Binary String Matching(string)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- NYOJ5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
随机推荐
- css3动画由浅入深总结
阅读目录 一:过渡动画---Transitions 二:Animations功能 三:translate(tx,ty) 四:scale(x,y) 五:rotate(x): 5.1:skew(x,y): ...
- [译]angularjs directive design made easy
原文: http://seanhess.github.io/2013/10/14/angularjs-directive-design.html AngularJS directives很酷 Angu ...
- Spring的问题解决记录
问题:在MyEclipse中项目工程重命名以后,例如 原来叫HttpService,改为GameApp,但是项目跑起来发现,tomcat服务器依旧为GameApp目录结构,访问也只能GameApp访问 ...
- jQuery的$.ajax示例
$.ajax({ url: 'index.php?module=products&submod=product_experience_manage&method=ajaxGetSele ...
- OS X 10.10.5编译Android5.1.1源码
--------------------------------------------------写在前面---------------------------------------------- ...
- 如何使用java自定义注解?demo
1.Description.java package kzfy.bk.com; import java.lang.annotation.Documented; import java.lang.ann ...
- HttpClient session
session概述 session机制 session机制是一种服务器端的机制,服务器使用一种类似于散列表的结构(也可能就是使用散列表)来保存信息. 当程序需要为某个客户端的请求创建一个session ...
- 35 网络相关函数(三)——live555源码阅读(四)网络
35 网络相关函数(三)——live555源码阅读(四)网络 35 网络相关函数(三)——live555源码阅读(四)网络 简介 5)NoReuse不重用地址类 6)initializeWinsock ...
- Python自动化之语法基础
1 第一个程序 hello world 在Linux环境下执行 vim hello.py #!/usr/bin/env python #指定解释器 print("hello world&qu ...
- 2.5---链表来进行加法,链式A+B(CC150)
这里是用了自己的方法,和书本不一样. import java.util.HashSet; import java.util.Set; class ListNode{ int val; ListNode ...