Substrings--poj1226(字符串)
Description
Input
Output
Sample Input
2
3
ABCD
BCDFF
BRCD
2
rose
orchid
Sample Output
2
2 题目大意:
给你n个字符串 要你找这n个字符串中最大的相同字串(字符串可以逆置) 分析:
先找到最小的母串 然后这个母串的所有字串从大到小 都和n个串循环一遍 只要找到符合的答案就跳出
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#define N 220
#define INF 0xffffffff
using namespace std; int main()
{
int T,n;
char str[N][N],s1[N],s2[N];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int Min=INF,b;
for(int i=; i<n; i++)
{
scanf("%s",str[i]);
if(strlen(str[i])<Min)
{
Min=strlen(str[i]);
b=i;
}
}
int len=Min,flag;
while(len)
{
for(int i=; i<=Min-len; i++)
{
flag=;
strncpy(s1,str[b]+i,len);
int k=;
for(int i=len-; i>=; i--)
{
s2[k++]=s1[i];
}
s1[len]=s2[len]='\0';
for(int i=; i<n; i++)
{
if(strstr(str[i],s1)==NULL && strstr(str[i],s2)==NULL)
{
flag=;
break;
}
}
if(flag==)
{
break;
}
}
if(flag==)
break;
len--;
}
printf("%d\n",len);
}
return ;
}
Substrings--poj1226(字符串)的更多相关文章
- Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】
A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重
#1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the nu ...
- Substrings 子字符串-----搜索
Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...
- Ruby:字符串处理函数
字符串处理函数1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fal ...
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
http://blog.csdn.net/rowanhaoa/article/details/38116713 A:Game With Sticks 水题.. . 每次操作,都会拿走一个横行,一个竖行 ...
- 2019NC#1
LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...
- POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串
题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS Memory Limit: 10000K Total ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 字符串(后缀数组):POJ 3415 Common Substrings
Common Substrings Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤ ...
随机推荐
- 关于 propertychange 兼容性问题
on 事件 $('body').on('property input','.class',function(){ alert(123); });
- FPGA-信号边缘检测
在FPGA逻辑电路中,输入信号的边缘检测是一个常用的操作,这算是FPGA的基本功之一. 信号边缘检测应用十分广泛,例如:通信协议的时序操作,按键的检测等,都应用到按键的检测.按键的检测分为上升沿和下降 ...
- js 字符串截取 substring() 方法、 substr() 方法、slice() 方法、split() 、join();
三种 js 截取字符串的方法: substring() 方法: substr() 方法: slice() 方法: 1.:substring() 方法:string.substring(from, to ...
- jquery命名冲突
nodeName是jquery的关键字
- 细说PHP-5.4 变量的类型
变量类型是指保存在该变量中的数据类型.计算机操作的对象是数据在计算编程语言世界里,每一个数据也都有它的类型,具有相同类型的数据才能彼此操作.例如书柜是装书用的.大衣柜是放衣服用的.保险柜是存放贵重物品 ...
- 如何改android device monitor文件的权限
adb.exe在c/Android/platform-tools目录下,在这个目录下打开终端,然后adb shell,然后su http://blog.csdn.net/u012719153/arti ...
- Caused by: java.lang.IllegalArgumentException: Parameter Maps collection does not contain value for com.bj186.crm.mapper.UserMapper.Integer
在使用SSM整合myBatis的过程中遇到了这个问题. 问题的原因: 把parameterType错误的写成了parameterMap 解决办法: 将parameterMap修改为parameterT ...
- HDU6199 gems gems gems (DP)
题意:有n颗石子 两个人轮流拿 如果上一个人拿了x颗 这个人就可以拿x或x+1颗 问先手能获得与后手的价值差最大是多少 题解:看起来是博弈 其实是DP dp[i][j][0/1]表示当前该0/1拿 拿 ...
- Java任务执行计时
Long startTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis(); endTime-star ...
- Fortran中常用函数列表
Y=INT(X) 转换为整数 ALL(所有型态) INTEGER Y=REAL(X) 转换为实数 INTEGER REAL Y=DREAL(X) 取复数实部(倍精度) COMPLEX*16 REAL* ...