南阳OJ----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 - 来源
- 网络
- 上传者
- naonao
-
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node
{
char a;
struct node *next;
}Node;
int i;
bool flag=true;
int main( void )
{
Node *head,*p1,*p2;
int t,n,count;
scanf("%d",&t);
getchar();
while(t--)
{
head=NULL;
count=n=;
p1=p2=( Node * )malloc( sizeof(Node) );
char str[]={'\0'};
gets(str);
//getchar();
while(p1->a=getchar(),p1->a!='\n')
{
if(n++==)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(Node*)malloc(sizeof(Node));
}
p2->next=NULL;
p1=head;
/* while(p1!=NULL)
{
putchar(p1->a);
p1=p1->next;
}
puts("");
*/
while(p1!=NULL)
{ while(p1!=NULL&&p1->a!=*str) //找到第一个位置
{
p1=p1->next;
}
if(p1!=NULL) //防止万一没有找到
{
p2=p1->next; for( ::i=; str[i]!='\0'; i++ )
{
if(str[i]==p1->a)
{
p1=p1->next;
}
else
{
::flag=false;
p1=p2;
break;
} if((p1==NULL&&str[i+]!='\0'))
{
::flag=false ;
break;
}
} if(::flag)
{
p1=p2 ;
count++;
}
else
::flag=true;
}
} free(head);
printf("%d\n",count); }
return ;
}
南阳OJ----Binary String Matching的更多相关文章
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- nyoj 题目5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 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 ...
- 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 ...
随机推荐
- c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library
介绍 一个c++ socket 客户端库 http://www.rudeserver.com/socket/index.html The RudeSocket™ Open Source C++ Soc ...
- [CF724B]Batch Sort(暴力,思维)
题目链接:http://codeforces.com/contest/724/problem/B 题意:给出n*m的数字阵,每行数都是1-m的全排列,最多可以交换2个数一次,整个矩阵可以交换两列一次. ...
- win8下安装matlab7.0
在win8下安装matlab7.0会出现一些兼容性的问题,需要设置系统环境变量,修改方式如下. 1.设置环境变量,方法:在你的安装目录的\MATLAB7\bin\win32有一个叫做atlas_Ath ...
- 容易混淆的url src href
新手刚学习的时候会分不清 url src href这些,不知道什么情况下应该用哪个.现在让我来理一理. url 统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网 ...
- kakfa的常用命令总结
Kafka的版本间差异较大,下面是0.8.2.1的操作方法 首先cd到kafaka的bin目录下; #step1启动zookeeper服务 nohup bin/zookeeper-server-s ...
- [转]-如何将Eclipse中的项目迁移到Android Studio 中
英文地址:http://developer.android.com/sdk/installing/migrate.html 翻译:Android Studio 中文组(大锤译) 如果你之前有用Ecli ...
- 阿里云大数据三次技术突围:Greenplum、Hadoop和“飞天”
阿里云大数据三次技术突围:Greenplum.Hadoop和"飞天" 对于企业来说,到底什么是云计算?相信很多企业都有这样的困惑,让我们一起回到这个原始的起点探讨究竟什么是云 ...
- poj1375Intervals(点到圆的切线)
链接 貌似这样的叫解析几何 重点如何求得过光源到圆的切线与地板的交点x坐标,可以通过角度及距离来算,如图, 根据距离和半径可以求得角度a.b.r,自然也可以求得d1,d2. 至于方向问题,在求r得时候 ...
- Oracle存储过程中异步调用的实际操作步骤
本文标签:Oracle存储过程 我们都知道在Oracle数据库的实际应用的过程中,我们经常把相关的业务处理逻辑,放在Oracle存储过程中,客户端以通过ADO来进行相关的调用 .而有些相关的业务逻辑 ...
- go中间的&和*
package main import "fmt" func main() { var a int = 1 var b *int = &a var c **int = &a ...