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≤ ...
随机推荐
- redis集群架构(含面试题解析)
老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...
- codevs 2046 孪生素数 3 (水题日常)
时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 在质数的大家庭中,大小之差不超过2的两个质数称它俩为一对孪生素数,如2和3.3和5 ...
- 洛谷 P1802 5倍经验日
题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi2011拿出了x个迷你装药物 ...
- Matlab 图像转极坐标系
实心圆环 imgVP1=flip(imgVP1,1); % 水平翻转 polarVP1=polarVolinPlot(imgVP1); % 调用函数空心圆环 [m,n,~]=size(imgVP2) ...
- 1-2 编程基础 GDB程序调试
简介 GDB是GNU发布的一款功能强大的程序调试工具.GDB主要完成下面三个方面的功能: 1.启动被调试程序 2.让被调试的程序在指定的位置停住. 3.当程序被停住时,可以检查程序状态(如变量值). ...
- 【转】Delphi 2010 Lite加装帮助文件
基于爱好,下载了一个delphi 2010 lite,业余玩玩. 不过这东西是网友重新打包的,没有带帮助.在网上搜索一下加摸索后搞定.步骤如下: Delphi 2010本身的帮助(MSDN风格的)1. ...
- vs2008控件查看器
使用 OLE/COM 对象查看器 通过读取控件的类型库,OLE/COM 对象查看器使您得以查看控件的接口. 使用 OLE/COM 对象查看器 单击“工具”菜单上的“OLE/COM 对象查看器”或在命令 ...
- 搜索 || BFS || POJ 3278 Catch That Cow
农夫在x位置,下一秒可以到x-1, x+1, 2x,问最少多少步可以到k *解法:最少步数bfs 要注意的细节蛮多的,写在注释里了 #include <iostream> #include ...
- vue+Java 前后端分离,多次请求Session不一致的问题(网络上找的)
在vue main.js中增加以下配置: import axios from 'axios'; axios.defaults.withCredentials=true; 请求时:设置 withCred ...
- C++友元函数和运算符重载
非成员友元函数.成员友元函数和友元类 1.友元的作用: (1)友元提供了不同类的成员函数之间.类的成员函数与一般函数之间进行了数据共享的机制: 2.友元的优点和缺点 优点:提高程序的运行效率: 缺点: ...