当前位置:网站首页>7-10 longest symmetric substring (25 points) (violence problem solution) C language
7-10 longest symmetric substring (25 points) (violence problem solution) C language
2022-04-23 05:33:00 【Ice Cream~】
For a given string , This problem requires you to output the length of the longest symmetric substring . for example , Given
Is PAT&TAP symmetric?
, The longest symmetric substring iss PAT&TAP s
, So you should output 11.Input format :
The input is given on a line, and the length is no more than 1000 Non empty string for .
Output format :
Output the length of the longest symmetric substring in one line .
sample input :
Is PAT&TAP symmetric?
No blank lines at the end
sample output :
11
No blank lines at the end
Ideas : End of string j=strlen(s)-1 Go ahead and find the front i=0 Same character , Then judge the previous character and the matching character interval
j-i+1 Whether the characters in the meet the palindrome , If meet , Then replace max The value is the interval value j-i+1. If not, then j Look forward to , After finding one side ,i++ Continue with the previous operation
#include<stdio.h>
#include<string.h>
int main()
{
char s[1002];
gets(s);
int max=1;
for(int i=0;i<strlen(s);i++)
{
for(int j=strlen(s)-1;j>=0;j--)
{
int left=i,right=j;
while(left<=right&&s[left++]==s[right--])// Traverse left~right Internal elements
{
if(left>right)// When left~right The condition is executed after traversing all elements in the scope
{
if(max<j-i+1)
{
max=j-i+1;
}
}
}
}
}
printf("%d",max);
return 0;
}
版权声明
本文为[Ice Cream~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220534525187.html
边栏推荐
- Create process memory management copy_ Mm - processes and threads (IX)
- After adding qmenu to qtoolbutton and QPushButton, remove the triangle icon in the lower right corner
- Usage and difference of shellexecute, shellexecuteex and winexec in QT
- Solve the problem of JS calculation accuracy
- Cmake basic tutorial (39) pkgconfig
- Pytorch deep learning practice_ 11 convolutional neural network
- Various situations of data / component binding
- SQL语句简单优化
- [no title] Click the classification jump page to display the details
- Cross domain CORS relationship~
猜你喜欢
弘玑|数字化时代下,HR如何进行自我变革和组织变革?
Create a tabbar component under the components folder, which is public
跨域CORS的情缘~
双击.jar包无法运行解决方法
Uniapp wechat sharing
Use of uniapp native plug-ins
The title bar will be pushed to coincide with the status bar
如果我是pm之 演出电影vr购票展示
Deep learning object detection
Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行
随机推荐
Differences between auto and decltype inference methods (learning notes)
CPT 104_ TTL 09
Multi process model in egg -- egg document Porter
点击添加按钮--出现一个框框(类似于添加学习经历-本科-研究生)
弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化
Similarities and differences between vector and array (notes)
JSON.
Basic knowledge of redis
字符识别easyocr
Use of uniapp native plug-ins
Laravel implements the Holy Grail model with template inheritance
Box collapse and margin collapse
Parsing of string class intern() method
Understand the relationship between promise async await
Xiuxian real world and game world
Cmake basic tutorial (39) pkgconfig
Golang通过exec模块实现Ping连通性检测案例
Knowledge of egg testing -- mock, Supertest, coffee
JVM memory and memory overflow exceptions (personal summary)
windows连接mysql出现ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost‘ (10061)