poj 3080 Blue Jeans (kmp暴力)
来源:互联网 发布:马油扫码软件 编辑:程序博客网 时间:2024/06/05 05:04
# include <stdio.h># include <algorithm># include <cstring>using namespace std;int next[100];char pat[100];char a[100][100];int ma;int lenp;int n;void Getnext(){ int i=0,j=-1; next[0]=-1; while(i<=lenp) { if(j==-1||pat[j]==pat[i]) j++,i++,next[i]=j; else j=next[j]; }}void kmp(){ int k,i,j,m; Getnext(); ma=100; for(k=1; k<n; k++) //匹配剩下的字符串 { i=0; j=0; m=0; while(i<60&&j<lenp)//每个匹配的最长长度 { if(j==-1||pat[j]==a[k][i]) { i++; j++; } else j=next[j]; if(j>m) m=j; } if(ma>m)//都要匹配中的最短 ma=m; }}int main (){ int t, i; char result[100]; char tmp[100]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i<n; i++) scanf("%s",a[i]); int ans=0; for(i=0; i<=59; i++) { strcpy(pat,a[0]+i);// 枚举第一个串的所有后缀串,strcpy lenp=60-i; kmp(); if(ma>ans) { ans=ma; strncpy(result,a[0]+i,ans);//strcnpy result[ans]='\0'; } else if(ma==ans)//输出字典序最小 { strncpy(tmp,a[0]+i,ans); tmp[ans]='\0'; if(strcmp(tmp,result)<0) strcpy(result,tmp); } } if(ans>=3) printf("%s\n",result); else printf("no significant commonalities\n"); } return 0;}
0 0
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans KMP+暴力
- poj 3080 Blue Jeans (kmp暴力)
- POJ 3080 Blue Jeans (KMP || 暴力)
- POJ 3080 Blue Jeans kmp+暴力枚举
- poj 3080 Blue Jeans 【KMP 暴力枚举】
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- poj 3080 Blue Jeans 【kmp+暴力】
- POJ 题目3080 Blue Jeans(KMP+暴力)
- POJ 3080 Blue Jeans(暴力枚举+kmp)
- POJ 3080 Blue Jeans (KMP+暴力枚举)【模板】
- POJ 3080 Blue Jeans——暴力 + kmp
- poj 3080 Blue Jeans 暴力
- POJ 3080 Blue Jeans KMP
- POJ 3080 Blue Jeans----kmp
- POJ 3080 Blue Jeans(KMP)
- POJ 3080 Blue Jeans KMP
- 关于对HAOI2014四道题的吐槽(非专业吐槽)
- 赛门铁克VCS(Veritas Cluster Server)双机日常管理
- some tips
- google代理
- JVM笔记——调优案例分析与实战
- poj 3080 Blue Jeans (kmp暴力)
- 华为机试 - 判断if语句括号是否匹配
- 使用ffmpeg转换文件格式,及ffmpeg参数说明
- hdu4948 Kingdom
- 事物处理它包含了一组数据库操作命令
- vim 基础
- 华为机试之 翻译电话号码
- 对于java 反射机制的理解
- 程序闪一下titlebar的问题