当前位置:网站首页>Codeup longest palindrome substring
Codeup longest palindrome substring
2022-06-22 22:40:00 【Douglas_ LT】
#pragma warning(disable :4996)
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include <stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int dp[5010][5010] = {
0 };
int main()
{
string str;
str.resize(5010, '\0');
vector<pair<char, int>>str_change;
scanf("%[^\n]", &str[0]);
int len1 = str.length();
for (int i = 0; i < len1; i++)
{
if (isalpha(str[i]))
{
str_change.push_back(make_pair(toupper(str[i]), i));
}
}
int len = str_change.size();
int maxn = 1;
for (int i = 0; i < len - 1; i++)
{
dp[i][i] = 1;
if (str_change[i].first == str_change[i + 1].first)
{
dp[i][i + 1] = 1;
}
}
dp[len - 1][len - 1] = 1;
int startn = 0, endn = 0;
for (int i = 0; i < len - 1; i++)
{
if (str_change[i].first== str_change[i + 1].first)
{
startn = i;
endn = i + 1;
maxn = 2;
break;
}
}
for (int j = 2; j <= len; j++)
{
for (int i = 0; i + j < len; i++)
{
if (str_change[i].first == str_change[i + j].first&&dp[i + 1][i + j - 1])
{
dp[i][i + j] = 1;
if (j + 1 > maxn)
{
maxn = j + 1;
startn = str_change[i].second;
endn = str_change[i + j].second;
}
}
}
}
for (int i = startn; i <= endn; i++)
{
cout << str[i];
}
return 0;
}
Bold style
边栏推荐
- Las point cloud create mesh
- Eureka服务注册与发现
- British teddy bear joins the pubg mobile game
- R language data Table data import practice: data Rename the name of the table data column (rename)
- How much do you know about the cause of amplifier distortion?
- CSV add a new column
- Summary of just meal with 900W increase in playback and acclaim from station B users
- [mavros] mavros startup Guide
- Install MySQL for Linux (package succeeded!!)
- LinkedList source code analysis
猜你喜欢

The xinjietu x70s has been listed for 87900 times and has leapfrogged the class in space safety. It is worthy of being a 7-seat SUV of the National University of China
![[Li mu] how to read papers [intensive reading of papers]](/img/86/4894bdef31d47d3f9bf3206b997eed.jpg)
[Li mu] how to read papers [intensive reading of papers]

Technology cloud report: East to West computing is not only about "computing", but also needs "new storage"
![[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design](/img/5d/71c75a3622f7814f385d04b6148074.png)
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design

liunx 安装mysql

SPA项目开发之首页导航+左侧菜单

How to carry out encryption protection for equipment under extortion virus rampant

Eureka服务注册与发现

大不列颠泰迪熊加入PUBG 手游

Rapideye, spot satellite remote sensing image data
随机推荐
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
Las point cloud create mesh
Implementation of breadth traversal adjacency matrix of 6-6 graph
Solve the problem that MySQL in phpstudy cannot be started and conflicts with locally installed MySQL
SPA项目开发之首页导航+左侧菜单
Las point cloud data thinning in ArcGIS
RapidEye快鸟、SPOT卫星遥感影像数据
Dynamic tree + data table + pagination of spa project development
British teddy bear joins the pubg mobile game
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
Is it bad for NFT that the market starts to cool down?
CYCA少儿形体礼仪 深圳市培训成果考核圆满落幕
二级造价工程师考前必备15个知识点来了!祝你旗开得胜!
[ROS introduction] cmakelist Txt and packages XML interpretation
Mask image modeling for self supervised representation pre training: CAE and its relationship with Mae and Beit
Solution to cache inconsistency
The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
Rendu stéréo
MySQL functions
[mavros] mavros startup Guide