HDU 1238 Substrings

来源:互联网 发布:适合苹果电脑设计软件 编辑:程序博客网 时间:2024/05/21 10:11

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1238

Substrings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7607    Accepted Submission(s): 3414


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
23ABCDBCDFFBRCD2roseorchid
 

Sample Output
22
找出所有字符串的公共子串,这些子串既可以是原串又可以是反转串。

枚举暴搜

下面是AC的代码

#include <stdio.h>#include <string.h>int yuan(char c){    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')        return 1;    return 0;}int main(){    int len,i;    char s[100000];    while(~scanf("%s",s) && strcmp(s,"end"))    {        int flag = 1;        len = strlen(s);        for(i = 0; i<len; i++)        {            if(yuan(s[i]))                break;        }        if(i>=len)            flag = 0;        for(i = 1; i<len; i++)        {            if(!flag)                break;            if(s[i] == s[i-1])            {                if(s[i]=='e' || s[i] == 'o')                continue;                flag = 0;                break;            }        }        for(i = 2; i<len; i++)        {            if(!flag)                break;            if(yuan(s[i]) && yuan(s[i-1]) && yuan(s[i-2]))                flag = 0;            else if(!yuan(s[i]) && !yuan(s[i-1]) && !yuan(s[i-2]))                flag = 0;        }        if(flag)            printf("<%s> is acceptable.\n",s);        else            printf("<%s> is not acceptable.\n",s);    }    return 0;}

0 0
原创粉丝点击