kmp 填空
来源:互联网 发布:网络平台运营方案模板 编辑:程序博客网 时间:2024/04/28 00:20
http://acm.fzu.edu.cn/problem.php?pid=1926
input
1
much of the language used to describe monetary policy such as steering the economy to a soft landing or a touch on the brakes makes it sound like a precise science nothing could be further from the truth @
3
much of the language _ _ describe monetary policy @
steering the economy to a _ landing @
much of the _ describe monetary @
一串字符,以@结尾,作为母串.
接下来n各子串,也已@作为结尾,子串中包含 _ 代表需要填写的单词,问,能不能匹配.
#include<stdio.h>#include<string.h>#include<string>using namespace std;int T,n,len_s,len_ss,pos,next[1111];char str[1111];string s[1111],ss[1111];void getnext(){ memset(next,0,sizeof(next)); int i=0,j=-1; next[i]=j; while(i!=len_ss){ if(j==-1||ss[i]==ss[j]||ss[i]=="_"||ss[j]=="_"){ //在这里加入判断就好了 next[++i]=++j; } else{ j=next[j]; } }}bool kmp(){ int i=0,j=0; while(i!=len_s&&j!=len_ss){ if(j==-1||s[i]==ss[j]||ss[j]=="_"){ //在这里加入判断 ++i;j++; if(j==len_ss){ return true; } } else{ j=next[j]; } } return false;}int main(){ scanf("%d",&T); int cas=1; while(T--){ pos=0; printf("Case %d:\n",cas++); while(1){ scanf("%s",str); if(strcmp(str,"@")==0){ break; } s[pos++]=string(str); } len_s=pos; scanf("%d",&n); while(n--){ pos=0; while(1){ scanf("%s",str); if(strcmp(str,"@")==0){ break; } ss[pos++]=string(str); } len_ss=pos; getnext(); if(kmp()){ printf("YES\n"); } else{ printf("NO\n"); } } } return 0;}
- kmp 填空
- fzu 1926 填空 【kmp字符串匹配】
- 填空
- 填空
- FZU Problem 1926 填空(KMP好题一枚,确实好)
- 准备填空
- 填空题
- linux填空
- 填空题
- 指针填空
- 指针填空
- 程序填空
- 程序填空
- 程序填空
- 数字填空
- 等式填空
- 填空题
- 填空题
- 百万邮做邮件营销的邮箱配置
- Yoga支撑PC+,联想引领传统PC突围
- JAVA从入门到提高—程序设计基础02
- 水晶报表
- C++ 用libcurl库进行http通讯网络编程
- kmp 填空
- python读取xml数据库中表内所有数据,获取数据库中所有表的字段名称
- SQL 2005 sa 密码修改
- Objective-C中NSDate,NSData类型与NSString类型转换
- C#获取网页内容的三种方式
- chapter2 算法——程序的灵魂
- Cocos2D与UIViewController混用
- 各种环境
- 中科院、腾讯、深圳明源研发团队管理经验分享