HDU_2594
2015-07-22 09:46
417 查看
//题意很简单,就是给定两个字符串,在第一个字符串中找到一个最大前缀作为第二个字符串的后缀.
AC代码:
AC代码:
#include<stdio.h> #include<string.h> #define N 50005 char t[N]; char s[N]; int next[N]; int len1; int len2; void get_next() { int i=0; int j=-1; next[0]=-1; while(i<len2) { if(j==-1||s[i]==s[j]) { i++; j++; next[i]=j; } else { j=next[j]; } } } void kmp() { int i=0; int j=0; while(i<len1) { if(j==-1||t[i]==s[j]) { i++; j++; } else { j=next[j]; } } if(!j) { printf("%d",j); } else { for(int k=0;k<j;k++) { printf("%c",s[k]); } printf(" %d",j); } printf("\n"); } int main() { while(scanf("%s%s",s,t)!=EOF) { len1=strlen(t); len2=strlen(s); get_next(); kmp(); } return 0; }
相关文章推荐
- HDOJ_Problem Archive_1002A + B Problem II
- Web开发概述及Tomcat服务器
- 动态类型语言和静态类型语言
- 【Android UI设计与开发】第15期:顶部标题栏(六)实现悬浮式顶部和底部标题栏效果
- oracle学习
- 设计模式之-----工厂方法模式
- HDOJ 2023 求平均成绩
- VBox搭建oracle 11g rac网络问题
- java.lang.NoSuchMethodException的错误
- 谈到一些传统的企业网站SEO问题领域
- 第三方开源库MBProgressHUD的功能扩展
- 238——Product of Array Except Self(数组,用空间换时间)
- 雀巢归巢,还能和年轻人的味蕾好好说话吗?
- [c语言]宏中 #和##的用法
- 启动自己浏览器app的方法
- C++中指针学习记录
- Running OFBiz
- ofbiz加载入eclipse
- jQuery图表开源软件
- android 获取Service(服务)的运行状态