当前位置:网站首页>codeup最长回文子串
codeup最长回文子串
2022-06-22 17:50: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;
}
加粗样式
边栏推荐
- 如何更改Apple Watch上的表盘
- UE4_ Ue5 make 3dui follow the camera orientation (attached works)
- Set of redis data structure
- Linked list 4- 21 merge two ordered linked lists
- 零基础学编程/学逆向/过检测(frida实战)
- Preliminary controller input of oculus learning notes (1)
- Dynamically changing the style of label elements in a loop
- exness整理马斯克收购推特需要解决三个问题
- 牛客网:判断是否为回文字符串
- Grafana 9 is officially released, which is easier to use and more cool!
猜你喜欢
Complete the sqlsession interface and implementation classes

腾讯云国际版云服务器欠费说明

牛客网:最小覆盖子串

2022年5月中国游戏厂商及应用出海 EMEA 地区收入30强

2022 R2 mobile pressure vessel filling test question simulation test platform operation

A course for New Oriental transformation bilingual live broadcast to bring goods to the project manager

如何持续突破性能表现? | DX研发模式

面试MySQL

C sqlsugar, hisql, FreeSQL ORM framework omni-directional performance test comparison sqlserver

JSP connection MySQL total error
随机推荐
Game NFT Market: opensea's most easily cut cake
exness整理马斯克收购推特需要解决三个问题
巴比特 | 元宇宙每日必读:传腾讯成立XR部门,元宇宙板块再次上涨,多家券商发报告关注虚拟人的投资机会...
centerOS 安装mangodb
wpa_ CLI parameter description
面试MySQL
如何在 FlowUs和Notion 等笔记软件中进行任务管理?
2022 operation of simulated examination platform for examination question bank of welder (elementary) special operation certificate
JVM快速入门
IPLOOK作为O-RAN联盟会员,将共同促进5G产业发展
PostgreSQL reconfigure from library
2022 Chongqing preschool education industry exhibition 𞓜 hi tech Toy Puzzle decompression Toy Expo
Mise en œuvre de redis par golang (10): transactions atomiques locales
Custom database connection pool class: requirement: enclose the collection class of a collection object
预训练语言模型,bert,RoFormer-Sim又称SimBERTv2
第四届青年生命科学论坛 | 第一轮通知
Does CDC 2.2.1 monitoring sqlserver not support monitoring multiple databases?
平安证券开户安全吗?它和平安银行是什么关系呢?
阿里云过户找不到账号安全组ID问题
The Fourth Youth Life Science Forum | first round notice