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>
#include <stdlib.h>
#include <windows.h>
void sort(char (*str)[]); //给字符串序列按长度排序
int fun(char (*str)[]); //求发现的最大的子串的长度
//char* in_turn(char* s); //字符串逆序 int main()
{
int t,n;
scanf("%d",&t);
while(t--) //提前判断范围
{
int i=;
char str[][]={};
scanf("%d",&n);
while(i<n)
{
scanf("%s",str[i++]); //gets会接收一个换行符
}
sort(str);
printf("%d\n",fun(str));
}
system("pause>nul");
return ;
} int fun(char (*str)[])
{
int max=,i,j,k;
char s[];
for(k=;str[][k];k++)
{
for(i=;i<=strlen(str[])-k;i++)
{
if(max>i) continue;
int flag=;
strcpy(s,str[]+k);//i-k+1
s[i]='\0';
for(j=;str[j][];j++)
{
if(strstr(str[j],s)==NULL && strstr(str[j],strrev(s))==NULL) //返回一个指向s1中第一次出现s2中字符串的位置,没有返回NULL
{flag=;break;} //strrev()逆序函数
}
if(flag==)
max=i;
}
}
return max;
}
/*
char* in_turn(char* str)
{
char _str[101];
int i;
for(i=0;str[i];i++)
{
_str[strlen(str)-1-i] = str[i];
}
_str[strlen(str)]='\0';
return _str;
}
*/
void sort(char (*str)[]) //一个指向100个char类型的指针
{
int i,j;
char temp[];
for(i=;str[i+][]!='\0';i++)
for(j=i+;str[j][]!='\0';j++)
{
if(strlen(str[i]) > strlen(str[j]))
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}

HDU_1238——最大子串搜索的更多相关文章

  1. Java 中字符串的子串搜索

    基友前两天参加了阿里的实习生面试,问了个问题,就是关于字符串的子串搜索的问题.想想实现方式无非就是两层循环,但是 java 中是有现成实现的,于是我就去查查源码,看看 java 语言怎么实现这个的,发 ...

  2. C++自定义String字符串类,支持子串搜索

    C++自定义String字符串类 实现了各种基本操作,包括重载+号实现String的拼接 findSubStr函数,也就是寻找目标串在String中的位置,用到了KMP字符串搜索算法. #includ ...

  3. Substrings 子字符串-----搜索

    Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...

  4. Leetcode 5. Longest Palindromic Substring(最长回文子串, Manacher算法)

    Leetcode 5. Longest Palindromic Substring(最长回文子串, Manacher算法) Given a string s, find the longest pal ...

  5. USACO 6.3 章节 你对搜索和剪枝一无所知QAQ

    emmm........很久很久以前 把6.2过了 所以emmmmmm 直接跳过 ,从6.1到6.3吧 Fence Rails 题目大意 N<=50个数A1,A2... 1023个数,每个数数值 ...

  6. [Golang]Go Packages

    ---------------------------------------------------------------------------------------------------- ...

  7. [转]后缀自动机(SAM)

    原文地址:http://blog.sina.com.cn/s/blog_8fcd775901019mi4.html 感觉自己看这个终于觉得能看懂了!也能感受到后缀自动机究竟是一种怎样进行的数据结构了. ...

  8. 字符串匹配算法1-KMP

    前面介绍过,字符串搜索一般来说有三种方式,前缀搜索,后缀搜索,子串搜索.KMP使用的是前缀搜索. 假设p的偏移是i,也就是窗口的位置是i,匹配到位置j+1时发现了不匹配.现在的问题是向前移动窗口到什么 ...

  9. Remoting接口测试工具

    动手写一个Remoting接口测试工具 基于.NET开发分布式系统,经常用到Remoting技术.在测试驱动开发流行的今天,如果针对分布式系统中的每个Remoting接口的每个方法都要写详细的测试脚本 ...

随机推荐

  1. IBinder对象在进程间传递的形式(一)

    命题 当service经常被远程调用时,我们经常常使用到aidl来定一个接口供service和client来使用,这个事实上就是使用Binder机制的IPC通信.当client bind servic ...

  2. hdu3308LCIS(线段树,点更新,段查寻,查寻时一定要注意跨越时如何计算)

    Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...

  3. Android 用ping的方法判断当前网络是否可用

    判断网络的情况中,有个比较麻烦的情况就是连上了某个网络,但是那个网络无法上网 ,,, = = 想到了用ping指令来判断,经测试,可行~ ~ ~ private static final boolea ...

  4. C#中hashtable的赋值、取值、遍历、排序操作

    一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,其 ...

  5. PHP博客小项目之知识点(1)

    一.博客系统介绍 Blog.Bloger.web log(网络日志) 博客主要发布一些文章.图片:博客一般都是个人博客: 博客的文章,一般都是按照时间倒序排列: 博客,仅音译,英文名为Blogger, ...

  6. Linux命令之进程的管理

    1.进程介绍 进程的分类: 进程一般分为交互进程.批处理进程和守护进程三类. 守护进程总是活跃的,一般是后台运行,守护进程一般是由系统在开机时通过脚本自动激活启动或由超级管理用户root来启动.比如在 ...

  7. ASP.NET-FineUI开发实践-10

    嵌套Grid,光棍月大放送,不藏着掖着.实在写的不好,没脸藏啊~只考虑显示排序修改什么的都不管! 话说三石官网加实例了,http://fineui.com/demo/#/demo/grid/grid_ ...

  8. 智能SQL优化工具--SQL Optimizer for SQL Server(帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 )

    SQL Optimizer for SQL Server 帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 SQL Optimizer for SQL Server 让 SQL Serve ...

  9. 最新 xode shareSDK使用分享

    shareSDK使用分享 什么是shareSDK ShareSDK实现第三方登录.分享.关注等功能. 为什么使用        快速,方便 如何使用 (1)官方下载ShareSDK        参照 ...

  10. 查找Mysql数据库连接jar包和对应的Driver和Url

    以前写jdbc连接向来都是直接copy,对于连接数据库的jar包在哪下载,对应的Driver类是哪一个,数据库连接串怎么找等等都没有做过,今天从零开始整了一遍. 使用的数据库是Mysql 一.已安装了 ...