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

记得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. RPC通信框架——RCF介绍

    现有的软件中用了大量的COM接口,导致无法跨平台,当然由于与Windows结合的太紧密,还有很多无法跨平台的地方.那么为了实现跨平台,支持Linux系统,以及后续的分布式,首要任务是去除COM接口. ...

  2. pandas把多个sheet读进一个DataFrame

    #!/usr/bin/python import pandas as pd import collections df_dict = pd.read_excel('c:\data\machines.x ...

  3. python Paramiko 模块远程管理主机

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- import paramiko import os, stat import sys import ope ...

  4. Coursera Algorithms week1 查并集 练习测验:2 Union-find with specific canonical element

    题目原文: Add a method find() to the union-find data type so that find(i) returns the largest element in ...

  5. Watchcow(欧拉回路)

    http://poj.org/problem?id=2230 题意:给出n个field及m个连接field的边,然后要求遍历每条边仅且2次,求出一条路径来. #include <stdio.h& ...

  6. Oracle_exp/expdp备份

    目录索引 1.exp和expdp的区别 2.expdp导出数据库流程 一.↓↓exp和expdp的区别↓↓ 1.exp和expdp最明显的区别就是导出速度的不同.expdp导出是并行导出(如果把exp ...

  7. POJ 3635 优先队列BFS

    (感谢lyd学长的幻灯片) 注意vis数组的应用 在vis[i][j]中 i表示到了第i个点 j表示还剩j升油 vis[i][j]表示最小话费. 这样只需搜到话费比它少的更新入堆就OK了 //By: ...

  8. Windows phone开发数据绑定系列(1)--了解数据绑定

    (部分内容参考MSDN文档) 数据绑定是在应用程序UI与业务逻辑之间建立连接的过程.通过数据绑定的方式实现了后台数据和前台UI元素的关联, 为用户提供了更好地交互体验. 数据绑定一般有以下几种体现方式 ...

  9. android黑科技系列——分析某直播App的协议加密原理以及调用加密方法进行协议参数构造

    一.前言 随着直播技术火爆之后,各家都出了直播app,早期直播app的各种请求协议的参数信息都没有做任何加密措施,但是慢慢的有人开始利用这个后门开始弄刷粉关注工具,可以让一个新生的小花旦分分钟变成网红 ...

  10. RRDtool入门详解

    ---------------原创内容,转载请注明出处.<yaoyao0777@Gmail.com>------------ 一.概述 RRDtool(round-robin databa ...