POJ1226(strstr)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13348 | Accepted: 4722 |
Description
Input
Output
Sample Input
2
3
ABCD
BCDFF
BRCD
2
rose
orchid
Sample Output
2
2
直接暴力枚举。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[][];
int n;
int solve()
{
char sub[];
char rsub[];
int len=strlen(s[]);
int cnt=;
for(int l=len;l>;l--)
{
for(int x=;x+l<=len;x++)
{
memset(sub,,sizeof(sub));
memset(rsub,,sizeof(rsub));
strncpy(sub,s[]+x,l);
strcpy(rsub,sub);
reverse(rsub,rsub+strlen(rsub));
cnt=;
for(int i=;i<n;i++)
{
if(strstr(s[i],sub)!=NULL||strstr(s[i],rsub)!=NULL)
{
cnt++;
}
else break;
}
if(cnt==n-) return strlen(sub);
}
}
return ;
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
memset(s,,sizeof(s));
for(int i=;i<n;i++)
{
scanf("%s",s[i]);
}
printf("%d\n",solve());
}
return ;
}
POJ1226(strstr)的更多相关文章
- POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串
题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS Memory Limit: 10000K Total ...
- [PHP源码阅读]strpos、strstr和stripos、stristr函数
我在github有对PHP源码更详细的注解.感兴趣的可以围观一下,给个star.PHP5.4源码注解.可以通过commit记录查看已添加的注解. strpos mixed strpos ( strin ...
- [LeetCode] Implement strStr() 实现strStr()函数
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- strstr 函数的实现
strstr函数:返回主串中子字符串的位置后的所有字符. #include <stdio.h> const char *my_strstr(const char *str, const c ...
- 28. Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Leetcode 详解(Implement strstr)
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- LintCode StrStr
1. 讨论目标字符串若为空, 则返回-1: 资源字符串若为空, 则返回-1. 2.讨论目标字符串个数为零, 则返回0: 资源字符串个数为零, 则返回-1. 3. 插入旗帜来使第二循环的结束为有条件地返 ...
- strstr函数
原型:char * strstr( char *haystack, char *needle ) 用法:#include <string.h> 功能:在haystack中寻找needle ...
- strstr函数的用法
C语言函数 编辑 包含文件:string.h 函数名: strstr 函数原型: extern char *strstr(char *str1, const char *str2); 语法: ...
随机推荐
- Spring核心(ioc控制反转)
IoC,Inversion Of Control 即控制反转,由容器来管理业务对象之间的依赖关系,而非传统方式中的由代码来管理. 其本质.即将控制权由应用程序代码转到了外部容器,控制权的转移就是 ...
- 百科知识 epub文件如何打开
.epub 简介 EPub是一个自由的开放标准,属于一种可以"自动重新编排"的内容:也就是文字内容可以根据阅读设备的特性,以最适于阅读的方式显示.EPub档案内部使用了XHTML或 ...
- ubuntu下调试ffmpeg程序出现undefined reference to pthread_once ,undefined reference to uncompress错误
Ubuntu(版本16.04)下默认配置编译Ffmpeg(版本4.1.3configure 添加选项--enable-threads),将编译好的ffmpeg库添加到程序 中进行编译出现undefin ...
- hdu5387(2015多校8)--Clock(模拟)
题目链接:点击打开链接 题目大意:给出一个时间,问在钟表上这个时间的时候.时针和分针的角度,时针和秒针的角度.分针和秒针的角度.假设不是整数以分数的形式输出. 假设依照最小的格来算,那么: 1s对于秒 ...
- remote connect openshift mysql
再虚拟机内 rhc port-forward <app-name> 此时,可以在本机 访问 127.0.0.1:8080 登陆 网页, 3306连接sql https://unix.st ...
- mysql_num_rows
mysql记录总条数 $sql3 = "select * from inviter where tuijianren = '$session' "; $res3 = mysql_q ...
- 版本控制器 git
摘要:版本控制器是码农必备的工具,很多常用的,像svn,git,cvs等,工作中用过svn,Tortoisehg,firefly,其实大同小异,现在简单介绍下git,以及它的一些常用命令. 在wind ...
- python super()(转载)
一.问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1: 代码段1: class A: def __init__(sel ...
- Struts2基本概念
一.Struts2体系结构 : 1.Web浏览器请求一个资源. 2.过滤器Dispatcher查找方法,确定适当的Action. 3.拦截器自动对请求应用通用功能,如验证和文件上传操作. 4.Acti ...
- 如何克隆UBUNTU14.04LTS
先对目标盘sdb做好处理,分区,格式化,挂载等操作sudo fdisk /dev/sdb1fdisk常用命令如下,m是帮助,n创建新分区,d删除分区,w保存退出.分好区后,对sdb1进行格式化和挂载: ...