国防科大校赛决赛-final(镜像赛) Problem A: XueXX and P-P String
2016-05-15 17:47
633 查看
Description
XueXX is a clever boy. And he always likes to do something with Palindrome String. What an interesting hobby!
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. A P-P String is a string, which can be divided into three parts with the same length, and part one jointing(拼接) part two generates a palindrome, and part two jointing part three generates a palindrome. That is to say, the string ”abccbaabc” is a P-P String because “abccba” is a palindrome and “cbaabc” is a palindrome.
XueXX’s friend Star can solve the problem whose string’s length is less than 100000. But XueXX cannot. Now give you a short string and can you help XueXX find the longest P-P String?
Input
The first line of input contains the number of test cases T(T<=10). The descriptions of the test cases follow: The first line of each test case contain a string which contains only lowercase letters. Note that the length of the string is less than 200.
Output
For each test case, output a single line containing the result standing the longest length.
Sample Input
3
aaabccbaabc
xxxxxxxxx
abcdefg
Sample Output
9
9
0
XueXX is a clever boy. And he always likes to do something with Palindrome String. What an interesting hobby!
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. A P-P String is a string, which can be divided into three parts with the same length, and part one jointing(拼接) part two generates a palindrome, and part two jointing part three generates a palindrome. That is to say, the string ”abccbaabc” is a P-P String because “abccba” is a palindrome and “cbaabc” is a palindrome.
XueXX’s friend Star can solve the problem whose string’s length is less than 100000. But XueXX cannot. Now give you a short string and can you help XueXX find the longest P-P String?
Input
The first line of input contains the number of test cases T(T<=10). The descriptions of the test cases follow: The first line of each test case contain a string which contains only lowercase letters. Note that the length of the string is less than 200.
Output
For each test case, output a single line containing the result standing the longest length.
Sample Input
3
aaabccbaabc
xxxxxxxxx
abcdefg
Sample Output
9
9
0
#include <iostream> #include <string.h> using namespace std; bool judge(int n, int m); char str[200]; int Palindrome(int n) { int i; int current = 0; for(i = 1; i <= (n+1)/3; i++) { if(judge(n, i)) current = i; } return current; } bool judge(int n, int m) { int i = n; int j = m; for(j = 1; j <= m ; j++, i--) { if((str[i] == str[i-2*m]) && (str[i] == str[i-2*m+2*j-1])) continue; else return 0; } return 1; } int main() { char arr[200]; int max; int m; int t; cin >>t; while(t--) { max = 0; for(int i = 0; i < 200; i++) arr[i] = 0; cin >> str; m = strlen(str); for(int i= 2; i < m; i++) { arr[i] = Palindrome(i); } for(int i = 2; i< m; i++) { if(max < arr[i]) max = arr[i]; } cout << max * 3 << endl; } return 0; }
相关文章推荐
- 国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard
- 国防科大校赛决赛-final(镜像赛) Problem B: XueXX and Binary
- Burp Suite使用详解
- 使用 Equinox 开发 OSGi 应用程序
- poj 1458 Common Subsequence
- 【LeetCode】95. Unique Binary Search Trees II
- Java源码学习 -- java.lang.StringBuilder,java.lang.StringBuffer,java.lang.AbstractStringBuilder
- php中include()和require()的区别
- LeetCode 60. Permutation Sequence
- 在Android Studio中进行单元测试和UI
- 【GIT】使用GIT GUI 连接到conding码库教程
- OC NSNumber NSValue
- Android中的UI
- 算法导论学习--快速排序--Quicksort
- [leetcode]347. Top K Frequent Elements
- MQTT协议 - Mosquitto安装测试
- J Arithmetic Sequence (华农第四届) 求数组中最长等差数列
- Ex2010-06 Get version number, build number
- android UI——2D绘图中应该注意的那些坑
- requirejs搭建前端框架