当前位置:网站首页>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 :
11No 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
边栏推荐
- (11) Vscode code formatting configuration
- The title bar will be pushed to coincide with the status bar
- 提升Facebook触及率和互动率攻略 | 智能客服帮您抓住用户的心
- Branch and loop statements
- Wbpack configuring production development environment
- Redis in node -- ioredis
- Laravel [view]
- QT compressed folder
- String class understanding - final is immutable
- es6数组的使用
猜你喜欢

Cross domain CORS relationship~

Create process memory management copy_ Mm - processes and threads (IX)

Uniapp wechat sharing

弘玑微课堂 | Cyclone RPA之“灵活的数字员工”执行器

(11) Vscode code formatting configuration

what is wifi6?

Pytorch deep learning practice_ 11 convolutional neural network
Basic knowledge of redis

open3d材质设置参数分析

双击.jar包无法运行解决方法
随机推荐
Interpretation of common SQL statements
catkin_package到底干了什么
what is wifi6?
Call the interface to get the time
史上最强egg框架的error处理机制
Why can't V-IF and V-for be used together
Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行
Create process memory management copy_ Mm - processes and threads (IX)
Basic knowledge of redis
selenium預先加載cookie的必要性
FileReader API file operation
修仙真实世界与游戏世界
Cmake basic tutorial (39) pkgconfig
提升Facebook触及率和互动率攻略 | 智能客服帮您抓住用户的心
Uniapp wechat sharing
Ehcache Memcache redis three caches
Edit, cancel, pull up menu
Formal parameters, local variables and local static variables
QSS, qdateedit, qcalendarwidget custom settings
IPI interrupt