好吧,这题直接搜索就可以了,不过要按照长度最短的来搜,很容易想得到。

记得ACM比赛上有这道题,呃。。不过,直接搜。。呵呵了,真不敢想。

 #include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std; char str[][];
char s1[],s2[]; int main(){
int T;
scanf("%d",&T);
while(T--){
int n; int min_p,minl=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",str[i]);
int tmp=strlen(str[i]);
if(minl>tmp){
min_p=i; minl=tmp;
}
}
for(int i=;i<=minl;i++){
bool flag=false;
for(int k=;k<=minl-i;k++){
int p;
for(p=;p<i;p++){
s1[p]=str[min_p][k+p];
s2[i-p-]=str[min_p][k+p];
}
s1[p]=s2[p]='\0';
// printf("%s\n%s\n",s1,s2);
int j;
for(j= ;j<=n;j++)
if(!strstr(str[j],s1)&&!strstr(str[j],s2))
break;
if(j>n){
flag=true;
break;
}
}
if(!flag){
printf("%d\n",i-);
break;
}
}
}
return ;
}

上面用到了一上strstr()的函数,这个是我从别处学来的,也写写,分析一下。

函数名: strstr  原型是朴素的字符串比较方法
功 能: 在字符串中查找指定字符串的第一次出现 
用 法: char *strstr(char *str1, char *str2); 
用法:#include <string.h> 
功能:

str1: 被查找目标

str2:要查找对象
该函数返回str2第一次在str1中的位置的指针,如果没有找到,返回NULL 


函数:find(),属于类string中一个函数。

包含在#include <string>中

功能较多,最常用的便是 string s.find(str)返回的是字符串str第一次在s中出现的位置。否则会返回一个很大的值s.npos

也可以使用s.find(str,5)表示从第5个位置开始查找,返回值和上面相同。

HDU 1238的更多相关文章

  1. (KMP 字符串处理)Substrings -- hdu -- 1238

    http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit:1000MS     Memory Limit:32768KB ...

  2. Substrings - HDU 1238(最大共同子串)

    题目大意:给你N个串,求出来他们的最大公共子串的长度(子串反过来也算他们的子串).   分析:很久以前就做过这道题,当时是用的strstr做的,不过相同的都是枚举了子串......还是很暴力,希望下次 ...

  3. hdu 1238 Substrings(kmp+暴力枚举)

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

  4. HDU 1238 Substing

    思路: 1.找出n个字符串中最短的字符串Str[N] 2.从长到短找Str[N]的子子串 subStr[N],以及subStr[N]的反转字符串strrev(subStr[N]):(从长到短是做剪枝处 ...

  5. hdu 2328 Corporate Identity(kmp)

    Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...

  6. HDU - 2328 Corporate Identity(kmp+暴力)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题意:多组输入,n==0结束.给出n个字符串,求最长公共子串,长度相等则求字典序最小. 题解:(居 ...

  7. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  8. Kuangbin 带你飞 KMP扩展KMP Manacher

    首先是几份模版 KMP void kmp_pre(char x[],int m,int fail[]) { int i,j; j = fail[] = -; i = ; while (i < m ...

  9. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

随机推荐

  1. leetcode二分查找相关

    目录 33/81搜索旋转排序数组 34在排序数组中查找元素的第一个和最后一个位置 35搜索插入位置 74搜索二维矩阵 300最长上升子序列,354俄罗斯套娃信封问题 33/81搜索旋转排序数组 假设按 ...

  2. (Go)04.go工作区目录规范及简单例子

    一.规范目录结构 D:\project\src\go_dev\day1\example1 二.设置GOPAH环境变量 三.hello world 1.hello world package main ...

  3. golang单点推送

    package main import ( "encoding/json" "flag" "fmt" "log" &qu ...

  4. B - Link/Cut Tree

    Problem description Programmer Rostislav got seriously interested in the Link/Cut Tree data structur ...

  5. C#Cookie操作类,删除Cookie,给Cookie赋值

    using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...

  6. js动态追加的元素如何触发事件

    一般通过js或者jQuery动态添加的元素标签,通过该元素标签.class.id触发事件,是无效的.如下所示: <body> <input type="text" ...

  7. # --with-http_sub_module模块

    作用: http内容替换 语法 第一种语法: sub_filter string:要替换的内容 替换后的内容 这个模块只能替换第一个匹配的字符串,如果需要匹配全部替换,则用到下面的第三种语法配置 第二 ...

  8. P1796 汤姆斯的天堂梦_NOI导刊2010提高(05)

    题目描述 汤姆斯生活在一个等级为0的星球上.那里的环境极其恶劣,每天12小时的工作和成堆的垃圾让人忍无可忍.他向往着等级为N的星球上天堂般的生活. 有一些航班将人从低等级的星球送上高一级的星球,有时需 ...

  9. jquery学习之$(document).ready()

    参考资料: 1.W3School在线教程:http://www.w3school.com.cn/jquery/event_ready.asp 2.某人博客园:http://www.cnblogs.co ...

  10. Android中ImageView的属性

    资源使用 Android 中支持三种格式的位图文件:.png(首选), .jpg(可接受),.gif(不建议) 为什么首推 PNG 呢? 官网的描述如下: 注:在构建过程中,可通过 aapt 工具自动 ...