poj 3080 字符串
来源:互联网 发布:python读音 编辑:程序博客网 时间:2024/05/21 20:23
题目原述
处理第一行 fi , 从len = 60 到 3 ,起点从i =0 ...m-1 枚举所有子串,跟1...n-1 行去比较;
函数 strncpy (目的存储地址,被复制的起始地址,长度) ; 最好手动加 目的数组【len】= '\0'
strcmp(s1,s2) : ==1 代表s1 字典序大于 s2 ;
#include<stdio.h>#include<string.h>#include<math.h>#include<string>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<list>#include<map>#include<set>using namespace std;const int m=60;char fi[m+10];char str[13][m+10];int n;char ans[m+10],tp[m+10];int la;//bool OK(int r,int j){// int st=0;// while(tp[st]){// if(tp[st]!=str[r][j])// return 0;// else// st++,j++;// }// return 1;//}//bool check(){//// for(int r=1;r<n;r++){// bool f1=1,f2=1;// for(int j=0;j<m;j++){// if(str[r][j]==tp[0]){// f1=0;// if(OK(r,j)){// f2=0;// break;// }// }// }// if(f1 || f2) return 0;// }// return 1;//}bool check(){ for(int r=1;r<n;r++){ bool f=1; for(int j=0;j<m;j++){ if(strstr(str[r]+j,tp)) f=0; } if(f) return 0; } return 1;}void deal(){ la=0; ans[0]=0; for(int len=m;len>2;len--){ for(int i=0;i<=m-len;i++){ strncpy(tp,fi+i,len); tp[len]=0; if(check()){ if(la==0) { strcpy(ans,tp); la=len; } else if(strcmp(ans,tp)>0) strcpy(ans,tp); } } if(la) return ; }}int main(){// freopen("in.in","r",stdin); int T; scanf("%d",&T); while(T--){ scanf("%d",&n); scanf("%s",fi); for(int i=1;i<n;i++) scanf("%s",str[i]); deal(); if(la<3) printf("no significant commonalities\n"); else printf("%s\n",ans); } return 0;}
0 0
- poj 3080 字符串
- POJ 3080 (字符串匹配)
- POJ 3080 字符串水题
- POJ 3080 Blue Jeans(字符串处理)
- poj 3080 Blue Jeans 字符串,暴力
- poj 3080 Blue Jeans kmp 字符串匹配
- POJ-3080 Blue Jeans(简单字符串)
- poj 3080 Blue Jeans 字符串匹配
- POJ 3080 Blue Jeans 字符串函数应用
- POJ 3080 Blue Jeans (分解字符串,KMP)
- POJ 2159 字符串加密
- POJ 2803 字符串识别
- POJ-1002(字符串+排序)
- poj 1002 字符串
- POJ 1056 字符串
- POJ 1028 字符串
- poj字符串总结
- poj 1002 string字符串
- 高效的开发团队需要什么人
- 网站通用后台框架代码,自适应显示器高度和宽度
- 纷纷改行当个韩国海军个海大富上
- NSMutableString常用函数
- 是的根深蒂固
- poj 3080 字符串
- Bluetooth in Android 4.2 and 4.3(一):综述
- 重要的手机短信丢失该怎么恢复
- 顺时针方向打印矩阵
- hao博文地址
- 9.5 触摸和手势:事件的传递的机制--演示代码
- UVA10250 The Other Two Trees
- uva 10250(数学)
- linux下文件打包和压缩