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 ...
随机推荐
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- 密码学初级教程(六)数字签名 Digital Signature
密码学家工具箱中的6个重要的工具: 对称密码 公钥密码 单向散列函数 消息认证码 数字签名 伪随机数生成器 提问: 有了消息认证码为什么还要有数字签名? 因为消息认证码无法防止否认.消息认证码可以识别 ...
- Android与Dalvik
自学android的同事说:Android 这个妈蛋!! 当初就应该选择c++/c 来开发.现在为了效率又搞ART.简直是折腾,art在android5.0 的时候就是默认了.前段时间还在学习andr ...
- pipe-filter 真难找啊
http://blog.csdn.net/absurd/article/details/4307903
- 正确理解JavaScript中的this关键字
JavaScript有this关键字,this跟JavaScript的执行上下文密切相关,很多前端开发工程师至今对this关键字还是模棱两可,本文将结合代码讲解下JavaScript的this关键字. ...
- Xcode如何找到默认的生成路径?
我最近刚刚入门ObjectiveC,在研习<Objective C程序设计(第6版)>一书. 今天看到有关文件和归档的章节,但是我对XCode的生成文件路径并不了解,然后,在调试代码的时候 ...
- Redis学习笔记五:独立功能之事务
Redis 事务提供了一种将多个命令请求打包,然后一次性.按顺序地执行多个命令的机制,并且在事务执行期间,服务器不会中断,会将事务中的所以命令都执行完毕才去处理其他客户端的命令请求. 事务的实现 事务 ...
- H5图像遮罩-遁地龙卷风
(-1)写在前面 这个idea不是我的,向这位前辈致敬.我用的是chrome49.用到的图片资源在我的百度云盘里http://yun.baidu.com/share/link?shareid=1970 ...
- webpack 教程 那些事儿05-多页应用
本篇主要关于如何用webpack构建多页应用 为什么要构建多页应用呢?因为我的项目本来就是多页应用啊至于为什么要用webpack?因为我要用vue啊,嫌gulp 每次打包慢 啊 文章目录 1. 利用v ...
- [Asp.net MVC]Asp.net MVC5系列——添加数据
目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...