acm之搜索题目1
来源:互联网 发布:自动生成声音软件 编辑:程序博客网 时间:2024/05/16 04:28
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
代码:
#include <stdio.h>#include <string.h>int main(){ char string[105][105],str[105],pos[105],inv[105]; int i,j,t,n,min_len,index; int flag; scanf("%d",&t); while(t--) { scanf("%d",&n); min_len = 105; for(i = 0; i < n; i++) { scanf("%s",string[i]); if(strlen(string[i])<min_len) { min_len = strlen(string[i]); index = i; } } int len; len = min_len; strcpy(str,string[index]); while(len>0) { flag = 0; for(i = 0; i <= min_len-len;i++) { flag = 1; strncpy(pos,str+i,len); for(j = 0;j<len;j++) inv[j] = pos[len-j-1]; pos[len] = inv[len] ='\0'; for(j = 0;j<n;j++) { if(strstr(string[j],pos)==NULL &&strstr(string[j],inv)==NULL) { flag = 0; break; } } if(flag)break; } if(flag)break; len--; } printf("%d\n",len); } return 0;}
- acm之搜索题目1
- acm之搜索题目2
- acm之搜索题目3
- acm之搜索题目4
- acm之搜索题目5
- acm之搜索题目6
- ACM搜索题目总结
- ACM搜索题目总结
- acm,关于搜索题目
- acm之递归题目1
- acm之母函数题目1
- acm之动态规划题目1
- acm之贪心算法题目1
- acm之pku题目分类
- acm题目之教主系列
- acm之pku题目分类
- ACM题目之泥塑课
- ACM题目之排列序数
- Centos接触 (七)安装JDK和tomcat
- 有关opencv光流法的解释
- 解决 ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
- EventBus 3.0使用基础
- 并发编程学习
- acm之搜索题目1
- C#操作word:将rtf中的ole对象通过MathType转换成MathML
- TCP数据报首部
- 如何来看单片机外设A/D转换器ADC0804时序图
- 设计模式总结
- 分布式系统里session同步的那些事儿
- Java基础知识
- Spring提供的单元测试
- Oracle数据库连接字符串(各种版本)