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 ...
随机推荐
- ecos编译redboot,vmware运行redboot,执行hello world(图形配置)
1- 下载源文件 :~/ecos$ ls -lrt total 80 drwxr-xr-x 7 XXXX XXXX 4096 Mar 27 2009 ecos-3.0 -rw-r--r-- 1 X ...
- Python计算机视觉3:模糊,平滑,去噪
我是一名初学者,如果你发现文中有错误,请留言告诉我,谢谢 图像的模糊和平滑是同一个层面的意思,平滑的过程就是一个模糊的过程. 而图像的去噪可以通过图像的模糊.平滑来实现(图像去噪还有其他的方法) 那么 ...
- python连接postgresql数据库
python可以通过第三方模块连接postgresql. 比较有名的有psycopg2 和python3-postgresql (一)psycopg2 ubuntu下安装 sudo apt-get ...
- Strategic game(POJ 1463 树形DP)
Strategic game Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 7490 Accepted: 3483 De ...
- MongoDB insert performance rapidly dropping
http://dba.stackexchange.com/questions/65554/mongodb-insert-performance-rapidly-dropping http://www. ...
- 【转】如何设置无线路由器的信道以获得最佳WIFI体验?
原文网址:http://jingyan.baidu.com/album/f25ef2546e28e4482c1b8225.html 现在随着移动互联网的发展,移动终端的普及,WIFI越来越必不可少,所 ...
- Word Search 解答
Question Given a 2D board and a word, find if the word exists in the grid. The word can be construct ...
- 【转】__attribute__机制介绍
1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量 ...
- Python的字符串与数字
Python3.0通过“input”实现读取控制台的输入与用户实现交互.值得注意的是input接受的所有数据都是字符串,即使输入的是数字,依然会被当作字符串来处理.这就会出现一些问题,所以需要进行类型 ...
- linux 修改文件、文件夹权限
# change owner of all the fies under dirName chown -R username dirName #change owner and the file gr ...