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≤ ...
随机推荐
- Clean Code 第十章 : 类
最近的CleanCode读到了第十章.这一张主要讲了如何去构造一个类,感觉的CleanCode至此已经不仅仅是单纯的讲如何'写'出漂亮的代码,而是从设计方向上去构造出好的代码了. 本章节主要讲了: * ...
- casting in C++
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=39 February 20, 2013 casting in C++ Fil ...
- 初探ABP--记一些常见的开发问题
1.Update-Database : 无法将“Update-Database”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. ...
- sublime text3前端开发插件配置以及使用(个人喜爱)
第一步下载软件接着Ctrl +~ (回车)把下面安装包管理添加到sublimeimport urllib.request,os; pf = 'Package Control.sublime-packa ...
- codevs 2600 13号星期几?
时间限制: 1 s 空间限制: 8000 KB 题目等级 : 黄金 Gold 题目描述 Description 从1900年1月1日(星期一) 开始经过的n年当中,每个月的13号这一天是星期一.星 ...
- DAX:New and returning customers
The New and Returning Customers pattern dynamically calculates the number of customers with certain ...
- Android(java)学习笔记164:开发一个多界面的应用程序之不同界面间互相传递数据(短信助手案例)
1.首先我们看看下面这个需求: 这里我们在A界面上,点击这个按钮"选择要发送的短信",开启B界面上获取网络上各种短信祝福语,然后B界面会把这些网络祝福语短信发送给A界面到" ...
- Encryption requires the OpenSSL PHP extension 报错
报错截图: 解决办法: 修改php.ini配置文件,打开该拓展 open php.ini search “opensll” remove the semicolon from: extension=p ...
- Visual Studio 安装VS10x CodeMAP
最近出差,用的是公司电脑,电脑安装的是Visual Studio 2017 VS10x CodeMap 支持Visual Studio 2010, 2012, 2013, 2015,不支持Visual ...
- 获得Dictionary所有key和value值
Dictionary<string, string> dc = new Dictionary<string, string>(); dc.Add("code" ...