PAT 1040 Longest Symmetric String
#include <cstdio>
#include <cstdlib> using namespace std; char line[];
char line2[]; int syslen(char str[], int start) {
int len = ;
int p = start - ;
int q = start + ;
while (p >= && str[q] != '\0' && str[p] == str[q]) {
p--, q++;
len += ;
}
return len;
} int main() {
scanf("%[^\n]s", line); int p = , q = ;
line2[p++] = ' ';
line2[p++] = line[q++];
while (line[q] != '\0') {
line2[p++] = ' '; // dummy char used as seperator
line2[p++] = line[q++];
}
line2[p++] = ' ';
line2[p] = '\0';
int max_len = ;
for (int i=; i<p; i++) {
int cur_len = syslen(line2, i);
if (cur_len > max_len) max_len = cur_len;
}
printf("%d", max_len/);
return ;
}
brute force for small case
PAT 1040 Longest Symmetric String的更多相关文章
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 1040. Longest Symmetric String (25)
题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...
- PTA (Advanced Level) 1040 Longest Symmetric String
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the lo ...
- PAT 甲级 1040 Longest Symmetric String
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...
- 1040 Longest Symmetric String (25分)(dp)
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 ...
- PAT甲题题解-1040. Longest Symmetric String (25)-求最长回文子串
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789177.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT (Advanced Level) 1040. Longest Symmetric String (25)
暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...
随机推荐
- CF138D World of Darkraft
$ \color{#0066ff}{ 题目描述 }$ n*m的格子,每个格子有字符'L','R',X',初始可以选择所有格子. 当选了 'L'的格子时,当前格子左下右上这条线上所有点不能选; 当选了 ...
- python wraps装饰器
这是一个很有用的装饰器.看过前一篇反射的朋友应该知道,函数是有几个特殊属性比如函数名,在被装饰后,上例中的函数名foo会变成包装函数的名字 wrapper,如果你希望使用反射,可能会导致意外的结果.这 ...
- FPGA基础学习(5) -- 时序约束(实践篇)
目录 1. 理论回顾 2. 时间裕量 3. 最大延迟和最小延迟 4. 案例分析 参考文献: 距离上一篇有关时序的理论篇已经有一段时间了(可以参考博文FPGA时序约束--理论篇),实际上此段时间,甚至到 ...
- ASP.NET后台取html控件值方式
1.Request.Form[“cbName”]: 可以在后台取到所有为name 为的控件的value值 2.可以通过 把html控件的值付给HiddenField,然后后台调用 3.就是自定义属性 ...
- python之文件读写(2)
2. 写入数据到文件中 读取文件用read,那么写用什么嘞?用write!实际操作一下. 2.1 简单的写入数据到文件中 file = open("write_data", &qu ...
- dotnet体系结构
一.C#与.NET的关系 1.粗略地説,.net是一种在Windows平台上的编程架构————一种API. 2.C#编译器专门用于.net,这表示用C#编写的所有代码总是使用.NET Framewor ...
- P2763 试题库问题
传送门 显然的网络流,源点向所有题目连流量为1的边,表示一题只能用一次,题目向它的所有类型连边,流量设为1,类型向汇点连边流量为题目需要的该类型的数量 然后最大流 如果最大流小于总需要的类型题目数量则 ...
- MITK 手册
可怜这么有用的开源竟然没有中文手册, MITK Plugin Manuals Overview The Basic Image Processing Plugin The DataManager ...
- Emit生成特定接口的类
参考 动态生成类 http://www w2bc com/Article/44799 http://www.cnblogs.com/yingql/archive/2009/03/24/1420914. ...
- tomcat普通用户启动不了
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these enviro ...