Substrings (C++ find函数应用)
Description
Input
<= 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.
Output
Sample Input
Sample Output
#include <iostream>
#include <string>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std; int main()
{
int t,n,i,j,k;
int mins;
int pos,flag,flag1;
string s[];
string key;
string tem;
string rev;
cin>>t;
while(t--)
{
cin>>n;
pos=;
flag=;
mins=INF;
for(i=;i<n;i++)
{
cin>>s[i];
if(s[i].length()<mins)
{
mins=s[i].length();
pos=i;
}
}
key=s[pos];
for(i=mins;i>=;i--)//子串长度
{
for(j=;j+i-<mins;j++)
{
tem=key.substr(j,i);//截取以j开头长度为i的子串
rev=string(tem.rbegin(),tem.rend());//反向迭代器,翻转后的子串
flag=;
flag1=;
for(k=;k<n;k++)
{
if(s[k].find(tem)==string::npos&&s[k].find(rev)==string::npos)
{
flag=;
break;
}//没有找到这样一个子串
}
if(flag)//找到了一个子串
{
cout<<i<<endl;
flag1=;
break;
}
}
if(!flag1)
{
break;
}
}
if(flag1)
{
cout<<<<endl;
}
}
return ;
}
Substrings (C++ find函数应用)的更多相关文章
- hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重
#1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the nu ...
- POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串
题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS Memory Limit: 10000K Total ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数014,tuple,元组
<zw版·Halcon-delphi系列原创教程> Halcon分类函数014,tuple,元组 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...
- Ruby:字符串处理函数
字符串处理函数1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fal ...
- 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版
<zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...
- postgres函数
1.数据修复最先考虑通过db内做修复,实在不行,在考虑外部应用程序通过jdbc修复. 比如一个场景:profile_image_url与enlarge_image_url都是微博用户信息返回的字段. ...
- hihocoder 1152 Lucky Substrings
#1152 : Lucky Substrings 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if t ...
- lua string函数
lua的string函数: 参数中的index从1开始,负数的意义是从后开始往前数,比如-1代表最后一个字母 对于string类型的值,可以使用OO的方式处理,如string.byte(s.i)可以被 ...
随机推荐
- python3: 数字日期和时间(1)
---恢复内容开始--- 1. 数字的四舍五入 Q: 你想对浮点数执行指定精度的舍入运算 A: 简单的使用内置的round(value, ndigits)函数即可. >>> roun ...
- 网络唤醒(WOL)全解指南:原理篇
什么是网络唤醒 网络唤醒(Wake-on-LAN,WOL)是一种计算机局域网唤醒技术,使局域网内处于关机或休眠状态的计算机,将状态转换成引导(Boot Loader)或运行状态.无线唤醒(Wake-o ...
- (转)python3 urllib.request.urlopen() 错误UnicodeEncodeError: 'ascii' codec can't encode characters
代码内容: url = 'https://movie.douban.com/j/search_subjects?type=movie'+ str(tag) + '&sort=recommend ...
- Redis系列五:redis键管理和redis数据库管理
一.redis键管理 1 键重命名 rename oldKey newkey //格式rename oldKey newKey //若oldKey之前存在则被覆盖set name james :set ...
- 连接远程数据库ORACLE11g,错误百出!
客户机中PLSQL DEV访问虚拟机中的ORACLE11g,错误百出! 创建时间: 2017/10/14 18:44 作者: CNSIMO 标签: ORACLE 忙了一下午,只有两个字形容:麻烦! ...
- jqgrid 设置隔行换色
有时,为美观效应,需要设置jqgrid隔行换色.jqgrid提供altRows属性来配置 启动隔行换色:altRows: true,//隔行换色 $("#filterGrid"). ...
- 设置ssh key后push为什么还要输入用户名和密码
$ git push Username for 'https://github.com': Password for 'https://Username@github.com': Counting o ...
- Docker中查看Mysql数据库中的各环境参数
通过官方的文档可以看到运行MySQL容器的命令是: docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mypwd -d mysql:tag 如:d ...
- 一文让您全面了解清楚HBase数据库的所有知识点,值得收藏!
一.HBase基本概念:列式数据库 在Hadoop生态体系结构中,HBase位于HDFS(Hadoop分布式文件系统)的上一层,不依赖于MapReduce,那么如果没有HBase这种Nosql数据库会 ...
- 20155211 网络对抗 Exp9 Web安全基础实践
20155211 网络对抗 Exp9 Web安全基础实践 基础问题回答 SQL注入攻击原理,如何防御? 原理:SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语 ...