POJ 3080 Blue Jeans(水~)
来源:互联网 发布:拜尔电动牙刷自慰知乎 编辑:程序博客网 时间:2024/06/03 09:24
Description
求m个长度为60的字符串的最长连续公共子串(2<=m<=10),规定:
1,最长公共串长度小于3不输出
2,若出现等长的最长的子串,则输出字典序最小的串
Input
多组输入,第一行为用例组数T,每组用例第一行为一整数m表示字符串个数,之后m行每行一个长度为60的字符串
Output
输出最长连续公共子串,最长公共串长度小于3输出no significant commonalities,若出现等长的最长的子串,则输出字典序最小的串
Sample Input
Sample Output
no significant commonalities
AGATAC
CATCATCAT
Solution
暴力枚举公共子串长度即可
Code
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn 65char p[maxn][maxn];char ans[maxn];int T,m;int main(){ scanf("%d",&T); while(T--) { scanf("%d",&m); for(int i=0;i<m;i++) scanf("%s",p[i]); int len=0; for(int i=0;i<strlen(p[0]);i++) for(int j=i+2;j<strlen(p[0]);j++) { char s[maxn]; strncpy(s,p[0]+i,j-i+1); s[j-i+1]='\0'; bool flag=true; for(int k=1;flag&&k<m;k++) if(strstr(p[k],s)==NULL) flag=false; if(flag&&(j-i+1>len||(j-i+1==len&&strcmp(ans,s)>0)))//更新最长长度和子串 { len=j-i+1; strcpy(ans,s); } } if(len<3)//长度小于3则不输出 printf("no significant commonalities\n"); else printf("%s\n",ans); } return 0;}
0 0
- POJ 3080 Blue Jeans(水~)
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- Poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- nim和面向对象(二)
- leetoj Search in Rotated Sorted Array
- Pleasant sheep and big big wolf (hdu 3046 最小割)
- ubuntu14.04下的搜狗输入法的安装
- 【Android Studio】android 自测工具monkey的使用
- POJ 3080 Blue Jeans(水~)
- Ubuntu OracleJDK离线安装教程
- Java中克隆机制
- 微信开发
- poj 1742 多重背包入门
- Coefficient of Variation(CV) DEMO
- 创业干货:牛逼的外衣,苦逼的内裤
- Spinner的Android:prompt无法显示文本
- linux文件目录命令