南阳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 ...
随机推荐
- dup2()函数的使用,
#define STR "xiamanman\n"#define STR_LEN 10#define STDOUT 1 #include <stdio.h>#inclu ...
- java读取文件多种方法
1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用 ...
- Metasploit RPC服务共享
1) 启动一个新的MSF RPC服务,-P参数后面指定连接到的RPC服务需要提供的口令,-U参数指定连接所需输入的用户名,使用-a 0.0.0.0将RPC服务绑定到所有的网络地址,否则服务默认只绑定到 ...
- 在服务器上log4net没写日志
登录到服务器上,发现log4net没写日志 在相应文件夹加上User用户的写权限后恢复正常了.
- [SAP ABAP开发技术总结]预定义(内置)数据类型
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- mysql密码忘记或者不知道,怎么办?
运行cmd: 输入mysql回车,如果成功,将出现MySQL提示符 > 连接权限数据库>use mysql; (>是本来就有的提示符,别忘了最后的分号) 修改改密码:> upd ...
- CSS笔记(六)链接
参考:http://www.w3school.com.cn/css/css_link.asp 链接的四种状态 ① a:link - 普通的.未被访问的链接 ② a:visited - 用户已访问的链接 ...
- .NET 4.0 任务和并行编程系列
8天玩转并行开发 8天玩转并行开发——第一天 Parallel的使用 8天玩转并行开发——第二天 Task的使用 8天玩转并行开发——第三天 plinq的使用 8天玩转并行开发——第四天 同步机制(上 ...
- 从POI到O2O 看百度地图如何走出未来之路
近期O2O的烧钱融资大战如火如荼,有人已经把O2O大战,用乌合之众的群体心理失控来形容.其实厂商都不傻,O2O烧钱大家都知道,但是大家还知道O2O背后这块大蛋糕价值"万亿级". 有 ...
- c 函数调用产生的汇编指令和数据在内存情况(1)
一直对函数调用的具体汇编指令和各种变量在内存的具体分配,一知半解.各种资料都很详细,但是不实践,不亲自查看下内存总不能笃定.那就自己做下. 两个目的: 一,函数和函数调用编译后的汇编指令基本样貌 二, ...