Substrings 子字符串-----搜索
Description
Input
Output
Sample Input
Sample Output
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#define maxn 105
char lina[maxn];
char a[maxn][maxn];
int x;
void linstr () //找出长度最小的字串
{
int i;
int len = 10000, lens;
lina[0]='\0';
scanf("%d", &x);
for (i = 0; i<x; i++)
{
scanf("%s", a[i]);
int lens = strlen(a[i]);
if (len>lens)
{
strcpy(lina, a[i]);
len = lens;
}
} }
int fin (char str[], char rts[]) //判断所提取的子串是否在所有字符串中出现
{
int i; for (i = 0; i<x; i++)
{
if (strstr(a[i], str)==0 && strstr(a[i], rts)==0)
return 0;
}
return 1;
} int fuck ()
{
int i, len, j;
len = strlen (lina);
for (i = len; i>0; i--)
{
for (j = 0; j+i<=len; j++)
{
char str[maxn]= {0}, rts[maxn];
strncpy(str, lina+j, i); //将lina中第j个开始的i个字符cpy到str中
strcpy(rts, str);
strrev(rts); //倒置函数 为了方便看题才用的 好多oj不支持倒置函数 需要自己再写一个函数完成倒置
if (fin(str, rts)==1) //判断str和他的倒置函数是否满足条件
return i;
}
}
return 0;
}
int main ()
{
int n, num; scanf("%d", &n);
while (n--)
{
linstr();
num = fuck();
printf("%d\n", num);
}
return 0;
}
Substrings 子字符串-----搜索的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [LeetCode] Count Binary Substrings 统计二进制子字符串
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- [LeetCode] Palindromic Substrings 回文子字符串
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
- [LeetCode] 647. Palindromic Substrings 回文子字符串
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
- 使用后缀数组寻找最长公共子字符串JavaScript版
后缀数组很久很久以前就出现了,具体的概念读者自行搜索,小菜仅略知一二,不便讨论. 本文通过寻找两个字符串的最长公共子字符串,演示了后缀数组的经典应用. 首先需要说明,小菜实现的这个后缀数组算法,并非标 ...
- Swift3.0语言教程查找字符集和子字符串
Swift3.0语言教程查找字符集和子字符串 Swift3.0语言教程查找字符集和子字符串,在字符串中当字符内容很多时,我们就需要使用到查找字符集或者子字符串的方法.以下我们将讲解3种查找字符集和子字 ...
- Java中String类常用方法(字符串中的子字符串的个数)
重点内容 4种方法: 1.int indexOf(String str)返回第一次出现的指定子字符串在此字符串中的索引. 2.int indexOf(String str, int startInde ...
- C#下利用正则表达式实现字符串搜索功能的方法(转)
关键字:正则表达式.元字符.字符串.匹配: 1.正则表达式简介:正则表达式提供了功能强大.灵活而又高效的方法来处:.NET框架正则表达式并入了其他正则表达式实现的: 2.字符串搜索:正则表达式语言由两 ...
- Java实现 LeetCode 730 统计不同回文子字符串(动态规划)
730. 统计不同回文子字符串 给定一个字符串 S,找出 S 中不同的非空回文子序列个数,并返回该数字与 10^9 + 7 的模. 通过从 S 中删除 0 个或多个字符来获得子字符序列. 如果一个字符 ...
随机推荐
- wordcount数据流过程解析
(1)执行hadoopFile()操作,其中有生成HadoopRDD的new 方法.然后执行map方法.pair => pair._2.toString,只对Value值进行操作.在textFi ...
- 常用WinPE
微PE工具箱:http://www.wepe.com.cn/ 绝对PE工具箱:http://dl.pconline.com.cn/download/64736.html 通用PE工具箱:http:// ...
- php数据库操作常用相关函数
MySQL访问函数都需要有相应的权限才能运行.常用的相关函数介绍如下: (1)integer mysql_connect(主机,用户名,口令); 此函数开始一个对指定主机上的MySQL数据库的连接.若 ...
- git checkout not discard changes
1. checkout one branch, show status user@vbox:/mnt/tmp$ git checkout masterSwitched to branch 'maste ...
- echo "hello" | nc -4t -w1 localhost 8001
TCP4: echo "hello" | nc -4t -w1 localhost 8001 UDP4: echo "hello" | nc -4u -w1 l ...
- Enumerable.SequenceEqual
Determines whether two sequences are equal by comparing the elements by using the default equality c ...
- 爬虫技术(四)-- 简单爬虫抓取示例(附c#代码)
这是我的第一个爬虫代码...算是一份测试版的代码.大牛大神别喷... 通过给定一个初始的地址startPiont然后对网页进行捕捉,然后通过正则表达式对网址进行匹配. List<string&g ...
- JavaScript——new Date().getMonth()
new Date().getMonth(); 说明:参照现在的月份,getMonth()返回的是0-11的数字,也就是说0=1月,1=2月……11=12月 当前的月份就是,new Date().get ...
- 转载]IOS LBS功能详解[0](获取经纬度)[1](获取当前地理位置文本 )
原文地址:IOS LBS功能详解[0](获取经纬度)[1](获取当前地理位置文本作者:佐佐木小次郎 因为最近项目上要用有关LBS的功能.于是我便做一下预研. 一般说来LBS功能一般分为两块:一块是地理 ...
- 查看Linux下端口占用情况的命令
在使用Linux系统的过程中,有时候会遇到端口被占用而导致服务无法启动的情况.比如HTTP使用80端口,但当启动Apache时,却发现此端口正在使用. 这种情况大多数是由于软件冲突.或者默认端口设置不 ...