http://acm.hdu.edu.cn/showproblem.php?pid=1238

Substrings

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 10   Accepted Submission(s) : 6

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.

Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string. 

Output

There should be one line per test case containing the length of the largest string found.

Sample Input

2
3
ABCD
BCDFF
BRCD
2
rose
orchid

Sample Output

2
2

直接枚举可能的字串,然后进行验证。

code:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std; string s[102];
int n;
bool check(string sub) {
int i, j;
string tmp;
for(i=0; i<sub.size(); i++)
tmp +=sub[ sub.size()-1-i];
for(i=0; i<n; i++)
if(s[i].find(sub)==s[i].npos && s[i].find(tmp)==s[i].npos)
return false;
return true;
}
void solve(int t,int p) {
string sub;
int i, j, k;
int ans =0;
for(i=0; i<t; i++)
for(j=t-1; j>=i; j--) {
if(j-i+1<ans) continue;
sub = s[p].substr(i,j-i+1);
if(check(sub)) {
if(j-i+1>ans) ans = j-i+1;
}
}
cout<<ans<<endl;
}
int main() {
// freopen("in.txt","r",stdin);
int T,i,t,sub_i, j;
cin>>T;
while(T--) {
cin>>n;
t = 200;
for(i=0; i<n; i++) {
cin>>s[i];
if(s[i].size()<t) {
t =s[i].size();
sub_i = i;
}
}
solve(t, sub_i);
}
return 0;
}


hdu1238 Substrings (暴力)的更多相关文章

  1. HDU-1238 Substrings

    Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  2. hdu1238 Substrings 扩展KMP

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. UVa 12718 Dromicpalin Substrings (暴力)

    题意:给定一个序列,问你它有多少上连续的子串,能够重排后是一个回文串. 析:直接暴力,n 比较小不会超时. 代码如下: #pragma comment(linker, "/STACK:102 ...

  5. KMP 、扩展KMP、Manacher算法 总结

    一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...

  6. POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串

    题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS   Memory Limit: 10000K Total ...

  7. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  8. Substrings(hdu1238)字符串匹配

    Substrings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  9. Java实现 蓝桥杯 算法提高VIP Substrings(暴力)

    试题 算法提高 Substrings 问题描述 You are given a number of case-sensitive strings of alphabetic characters, f ...

随机推荐

  1. xgboost gbdt特征点分烈点

    lightGBM与XGBoost的区别:(来源于:http://baijiahao.baidu.com/s?id=1588002707760744935&wfr=spider&for= ...

  2. ThinkPHP联表查询

    $list = db($pnav['ename']) -> field('a.*,b.name as pname') ->alias('a') -> join('sbl_nav b' ...

  3. MySQL基础 - 数据库备份

    出于安全考虑,数据库备份是必不可少的,毕竟对于互联网公司数据才是价值的源泉~ 距离mysql账号为icebug,密码为icebug_passwd, 数据库为icebug_db mysqldump -u ...

  4. wpf 在Popup内的TextBox 输入法 不能切换

    切换输入法 输入不了中文 [DllImport("User32.dll")] public static extern IntPtr SetFocus(IntPtr hWnd); ...

  5. (四)Jsoup 获取 DOM 元素属性值

    第一节: Jsoup 获取 DOM 元素属性值 Jsoup获取DOM元素属性值 比如我们要获取博客的href属性值: 我们这时候就要用到Jsoup来获取属性的值 : 我们给下示例代码: package ...

  6. git/github 生成密钥

    当从本地提交文件到github的时候,提交不成功,报错,可能问题就是你还没有生成ssh秘钥 github要使用ssh密钥的原因: git使用https协议,每次pull, push都要输入密码,相当的 ...

  7. Redis(四)Redis高级

    一Redis 数据备份与恢复 Redis SAVE 命令用于创建当前数据库的备份. 语法 redis Save 命令基本语法如下: redis 127.0.0.1:6379> SAVE 实例 r ...

  8. 铁轨(UVa 514)

    利用栈实现 C++11 代码如下: #include<iostream> #include<stack> using namespace std; #define maxn 1 ...

  9. HTML5 Canvas游戏开发(四)lufylegend开源库件(下)

    一.文本 LTextField对象是lufylegend库件中专门用于显示文本信息的一个对象. 1.文本属性 创建的文本框对象不会自动加入可视化对象列表中.只有手动调用addChild()方法才能使它 ...

  10. JSTL使用

    1.标签函数库 核心标签库                 c I18N格式标签库   fmt SQL标签库  sql XML标签库  xml 函数标签库 fn 2.JSTL支持EL 二:表达式标签 ...