博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenJudge/Poj 1226 Substrings
阅读量:5854 次
发布时间:2019-06-19

本文共 2291 字,大约阅读时间需要 7 分钟。

1.链接地址:

http://bailian.openjudge.cn/practice/1226/

http://poj.org/problem?id=1226

2.题目:

总时间限制:
1000ms
内存限制:
65536kB
描述
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.
输入
The first line of the input 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.
输出
There should be one line per test case containing the length of the largest string found.
样例输入
23ABCDBCDFFBRCD2roseorchid
样例输出
22
来源
Tehran 2002 Preliminery

3.思路:

 

4.代码:

1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 const int NUM = 100; 8 char strs[NUM][NUM + 1]; 9 int main()10 {11 //freopen("F:\\input.txt","r",stdin);12 int i,j,k;13 14 int t;15 cin>>t;16 17 int n,length;18 while(t--)19 {20 cin>>n;21 cin.get();22 23 for(i = 0; i < n; i++)24 {25 scanf("%s",strs[i]);26 }27 28 for(i = 0; i < n; i++)29 30 length = strlen(strs[0]);31 char substr[NUM + 1],substr2[NUM + 1];32 int res = 0;33 for(i = 1; i <= length; i++)34 {35 for(j = 0; (j+i-1) < length; j++)36 {37 strncpy(substr,&strs[0][j],i);38 substr[i] = '\0';39 strcpy(substr2,substr);40 41 for(k = 0; k < (i+1)/2; k++)42 {43 char tmp = substr2[k];44 substr2[k] = substr2[i-1-k];45 substr2[i-1-k] = tmp;46 }47 48 49 //cout<<"substr="<
<<",substr2="<
<
= n ) 55 {56 res = i;57 break;58 }59 }60 }61 62 cout<
<

 

转载于:https://www.cnblogs.com/mobileliker/p/3551994.html

你可能感兴趣的文章
commandLink/commandButton/ajax backing bean action/listener method not invoked (转)
查看>>
软件工作的大环境
查看>>
梅沙教育APP简单分析-版本:iOS v1.2.21-Nathaneko-佳钦
查看>>
Word中如何设置图片与段落的间距为半行
查看>>
Windows Server 2008 RemoteApp---发布应用程序
查看>>
白帽子技术分析会话劫持实战讲解
查看>>
我的友情链接
查看>>
yum的三种方式
查看>>
Redis分布式缓存安装和使用
查看>>
20天精通 Windows 8:系列课程资料集
查看>>
html5 <figure> 标签
查看>>
开源监控软件 Hyperic 的两种插件
查看>>
TOMCAT
查看>>
Spark学习记录(二)Spark集群搭建
查看>>
php引用(&)详解及注意事项
查看>>
短信猫JAVA二次开发包SMSLib,org.smslib.TimeoutException: No response from device解决方案...
查看>>
CloudStack 4.4学习总结之cloudstack-management安装
查看>>
protocol buffer安装及使用(非常详细)
查看>>
VTSS Error code
查看>>
360提供的Php防注入代码
查看>>