Substrings(hd1238)
Substrings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8183 Accepted Submission(s):
3752
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.
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.
length of the largest string found.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
/* 原型:char * strncpy(char *dest, char *src, size_t n); 功能:将字符串src中最多n个字符复制到字符数组dest中(它并不像strcpy一样只有遇到NULL才停止复制,而是多了一个条件停止,就是说如果复制到第n个字符还未遇到NULL,也一样停止),返回指向dest的指针。*/
int main()
{
int N,i,j,num;
freopen("in.txt","r",stdin);
cin>>N;
while(N--)
{
char string[][],pos[],inv[],str[];
int min_str=,index,len,flag=;
cin>>num;
for(i=;i<num;i++)
{
cin>>string[i];//相当于把\n换成'\0';
if(strlen(string[i])<min_str)
min_str=strlen(string[i]);
index=i;
}//输入字符串,并找到短字符串
len=min_str;
strcpy(str,string[index]);
while(len>)
{
for(i=;i<=min_str-len;i++)//对于len长的子串可以取多少种;从最长的开始取
{
flag=;//假设该子串符合
strncpy(pos,str+i,len);//并不会把'\0'复制进去,自己加进去
for(j=;j<len;j++)
inv[j]=pos[len-j-];//求出逆向子串;
inv[len]=pos[len]='\0';
for(j=;j<num;j++)
{
if(strstr(string[j],inv)==NULL&&strstr(string[j],pos)==NULL)
{
flag=;
break;
}
}
if(flag)
break;
}
if(flag)
break;
len--;
}
cout<<len<<endl;
}
}
Substrings(hd1238)的更多相关文章
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- Substrings(hdu1238)字符串匹配
Substrings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Java实现 蓝桥杯 算法提高VIP Substrings(暴力)
试题 算法提高 Substrings 问题描述 You are given a number of case-sensitive strings of alphabetic characters, f ...
- [CF1538E] Funny Substrings (模拟)
题面 该场 Div. 3 最"难"的一道题:Funny Substrings O I D \tt OID OID 队长喜欢玩字符串,因为 " O n e I n D a ...
- HDU-4455 Substrings(DP)
题目大意:给一个长度为n的整数序列,定义egg(i,j)表示区间[i,j]中不同的数的个数.q次询问,每次询问x,表示求所有长度为x连续区间的 egg 之和. 题目分析:定义dp(len)表示所有长度 ...
- 【SPOJ694】Distinct Substrings (SA)
求不相同子串个数 该问题等价于求所有后缀间不相同前缀的个数..也就是对于每个后缀suffix(sa[i]),将贡献出n-sa[i]+1个,但同时,要减去那些重复的,即为height[i],故答案 ...
- C - Distinct Substrings (模板)
https://vjudge.net/problem/SPOJ-DISUBSTR 有两种方式来求去除重读的子串 #include <bits/stdc++.h> using namespa ...
- 【CF1029A】Many Equal Substrings(模拟)
题意:给定一个长度为n的串s,要求构造一个长度最小的使s出现了k次的串,可以重叠 n<=50,k<=50 思路:计算一下前后缀相同长度 #include<cstdio> #in ...
- poj 3415 Common Substrings(后缀数组+单调栈)
http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS Memory Limit: 65536K Total Sub ...
随机推荐
- 有关PHP中点击下载文件的小功能
最近需要在项目里加一个可以点击导出树状目录的目录结构图, 我在网上查了之后,发现基本千篇一律, 都是使用下面这种header函数, 直接去readfile() 这个文件 header('Content ...
- js控制浏览器后退
<script type="text/javascript"> window.history.forward(1); </script>
- Laravel 模板引擎Blade中标签详细介绍
这篇文章主要介绍了Laravel模板引擎Blade中section的一些标签的区别介绍,需要的朋友可以来看看. Laravel 框架中的Blade模板引擎很好用,但是官方文档介绍的并不详细,我接下来将 ...
- ruby更换为淘宝的源
我们在使用gem更新的时候,经常会为速度抓狂,其实gem默认的源是https://rubygems.org,比较慢众所周至的原因了. 可以将源更换到国内的taobao源 查看当前有的源 gem sou ...
- python 连接Mysql数据库
1.下载http://dev.mysql.com/downloads/connector/python/ 由于Python安装的是3.4,所以需要下载下面的mysql-connector-python ...
- MVC5学习相关资源整理
1 官方 Getting Started http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started 英文不好,英文好的同 ...
- 为什么选择使用 Dropbox 而不是其他品牌同步工具(不要加上多余的功能,要极致和专注)
作者:吴锋链接:http://www.zhihu.com/question/19646859/answer/14707821来源:知乎著作权归作者所有,转载请联系作者获得授权. 窃以为楼主的问题,准确 ...
- C语言的本质(34)——静态库
库是一种软件组件技术,库里面封装了数据和函数. 库的使用可以使程序模块化. Windows系统包括静态链接库(.lib文件)和动态链接库(.dll文件). Linux通常把库文件存放在/usr/lib ...
- 一次使用Eclipse Memory Analyzer分析Tomcat内存溢出
转:http://tivan.iteye.com/blog/1487855 前言 在平时开发.测试过程中.甚至是生产环境中,有时会遇到OutOfMemoryError,Java堆溢出了,这表明程序有严 ...
- 分治法求一个N个元素数组的逆序数
背景 逆序数:也就是说,对于n个不同的元素,先规定各元素之间有一个标准次序(例如n个 不同的自然数,可规定从小到大为标准次序),于是在这n个元素的任一排列中,当某两个元素的先后次序与标准次序不同时, ...