1040 Longest Symmetric String
1040 Longest Symmetric String (25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?
, the longest symmetric sub-string is s PAT&TAP s
, hence you must output 11
.
Input Specification:
Each input file contains one test case which gives a non-empty string of length no more than 1000.
Output Specification:
For each test case, simply print the maximum length in a line.
Sample Input:
Is PAT&TAP symmetric?
Sample Output:
11
解析:基础的字符串处理。
#include<bits/stdc++.h>
using namespace std;#define ee exp(1)
#define p acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}string s;
int symmetric(string str,int i,int j)
{int x=i,y=j;for(;i<=(x+y)/2;i++){if(s[i]!=s[j--])return 0;}return true;
}
int main()
{getline(cin,s);int maxlen=1;for(int i=0; i<s.size(); i++){for(int j=i; j<s.size(); j++){if(symmetric(s,i,j))maxlen=max(maxlen,j-i+1);}}printf("%d\n",maxlen);return 0;
}
1040 Longest Symmetric String相关推荐
- 1040. Longest Symmetric String (25)
题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...
- PAT 甲级 1040 Longest Symmetric String
1040 Longest Symmetric String 题目大意:给出一个字符串,求出最长的回文子串的长度 思路:从第一个字符开始往后遍历,每次遍历第一个字符不动,从下一个字符开始找起,若是有回文 ...
- PAT 1040 Longest Symmetric String (25)
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- 1040 Longest Symmetric String (25 分)_15行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a string, you are supposed to output the length of the long ...
- 1040. Longest Symmetric String (25)-PAT甲级真题
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- 1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- 1040 Longest Symmetric String 需再做
解题思路 本题属于最长回文子串专题下.与之前的LIS和LCS的动规有两个较大的不同 1. 虽然最后也是要求长度,但是长度信息不再蕴含在dp数组当中,dp[i][j]表示的仅仅是从s[i]起s[j]止这 ...
- 1040 Longest Symmetric String (25 分)【难度: 一般 / 知识点: 最长回文子串】
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 方法一: 最朴素的做法, 枚举所有的子串 # ...
- 浙大pat1040 Longest Symmetric String(25 分)
1040 Longest Symmetric String(25 分) Given a string, you are supposed to output the length of the lon ...
最新文章
- 【深度好文】沈向洋:读论文的三个层次
- 企业网络推广——企业网络推广专员讲述网站友链交换如何做
- 修改Oracle中的某一带有数据的列的数据类型
- R语言:na.fail和na.omit
- 3D Button Visual Editor
- 操作系统,,,也考完了【流坑】
- java 静态代码块_关于Java你不知道的那些事之代码块
- BDS-HA:构建高可用、低延迟的HBase服务
- cocos2d-x的popScene的动画效果
- 【Linux】VirtualBox安装ubuntu排错LowGraphic
- OpenCV resize 图像缩放
- python中通过index删除list中的多个元素
- Asp.net MVC3 WebGrid查询绑定
- word——VBA编程
- cpu多开测试软件,游戏多开CPU优化工具
- LaTex 常用数学公式符号速记
- Vue+Element 表格打印
- 计算机中重命名的英文单词,重命名是什么意思
- python处理图片去白底-Python实现将蓝底照片转化为白底照片功能完整实例
- 纯小白适合了解的3D游戏建模科普知识,通过培训能入行吗?