POJ 3080 (字符串水题) Blue Jeans
2014-11-26 17:02
429 查看
题意:
找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个。
分析:
用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀。
代码君
找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个。
分析:
用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀。
#include <cstdio> #include <cstring> char a[15][70], sub[70]; int p[70], l; int cmp(int p1, int p2) { for(int i = 0; i < l; ++i) if(a[0][p1 + l] > a[0][p2 + l]) return p2; return p1; } int main(void) { //freopen("3080in.txt", "r", stdin); int T; scanf("%d", &T); while(T--) { int n, cnt = 0; scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%s", a[i]); for(l = 60; l >= 3; --l) { cnt = 0; for(int pos = 0; pos <= 60 - l; ++pos) { char temp = a[0][pos + l]; a[0][pos + l] = '\0'; bool flag = true; for(int i = 1; i < n; ++i) { if(strstr(a[i], a[0] + pos) == NULL) { flag = false; break; } if(!flag) break; } a[0][pos + l] = temp; if(flag) p[cnt++] = pos; } if(cnt > 0) break; } if(cnt == 0) { puts("no significant commonalities"); continue; } int min = p[0]; for(int i = 1; i < cnt; ++i) min = cmp(min, p[i]); a[0][min + l] = '\0'; printf("%s\n", a[0] + min); } return 0; }
代码君
相关文章推荐
- POJ 3080 Blue Jeans(字符串处理)
- POJ-3080 Blue Jeans(简单字符串)
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
- POJ 3080:Blue Jeans:枚举求解n个字符串的最长公共连续子串
- 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 字符串,暴力
- 【原】 POJ 3080 Blue Jeans KMP 解题报告
- POJ 3080 Blue Jeans
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans KMP+ 枚举
- POJ-3080 Blue Jeans 暴力
- 3080 Blue Jeans 求N个字符串的最长子串 暴力枚举+ KMP模板
- poj 3080 kmp水题
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans(KMP模式匹配)
- POJ 3080 Blue Jeans