Usaco section 1.3:calf Flac (CALFFLAC)

Source: Internet
Author: User

Test instructions: It is said that if you give unlimited cows and unlimited giant laptops (with very large keyboards), cows will make the best palindrome in the world. Your job is to find the wonders (the best palindrome) that these cows make. When looking for a palindrome, ignore the punctuation marks, spaces (but should be retained for the answer output), only consider the letters ' a '-' Z ' and ' a '-' Z '. The longest palindrome article you are looking for is a string of no more than 20,000 characters. We will guarantee that the longest palindrome will not exceed 2,000 characters (before punctuation, whitespace is removed).

Violence note Some details enter the character with a carriage return ah such as wins down after you press ENTER CTRL + Z and press ENTER.

Under Ubuntu is CTRL + Z

Code:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define SSS (A,B,C) scanf ("%d%d%d", &a,&b,&c)
#define MEM1 (a) memset (A,-1,sizeof (a))
#define MEM (a) memset (A,0,sizeof (a))
#define SS (A, B) scanf ("%d%d", &a,&b)
#define S (a) scanf ("%d", &a)
#define INF 0x3f3f3f3f
#define W (a) while (a)
#define PI ACOs (-1.0)
#define LL Long Long
#define EPS 10E-9
#define N 100010<<1
#define MOD 1000000000+7
using namespace Std;
void Mys (int& res)
{
int flag=0;
Char ch;
while (!) ( ((Ch=getchar ()) >= ' 0 ' &&ch<= ' 9 ') | | ch== '-'))
if (ch==eof) Res=inf;
if (ch== '-') flag=1;
else if (ch>= ' 0 ' &&ch<= ' 9 ') res=ch-' 0 ';
while ((Ch=getchar ()) >= ' 0 ' &&ch<= ' 9 ') res=res*10+ch-' 0 ';
Res=flag?-res:res;
}
void Myp (int a)
{
if (a>9)
MYP (A/10);
Putchar (a%10+ ' 0 ');
}
/********************the End of template********************/
struct node{
Int St, Ed, lenth;
}s;
struct strtr{//Copy
int POS;
char c;
}STRT[20001];
Char str[20001];
BOOL Can (char x, char y) {
if (x = = y | | (x-y = = (' A '-' a ')) | | (Y-x = = (' A '-' a '))) return true;
return false;
}
int main () {
Int J, K;
Char ch;
int top = 0, len = 0;
W ((ch = getchar ())! = EOF) {
str[len++] = ch;
if (Isalpha (CH)) {
STRT[TOP].C = ch;
Strt[top++].pos = len-1;
}
}
S.lenth =-1;
for (int i = 0; i < top; i + +) {
if (strt[i].c! = strt[i+1].c) {
for (j = i-1, k = i+1; j>=0 && k<top; J--, k++) {
if (!can (STRT[J].C, strt[k].c)) break;
}
}
else{
for (j = i-1, k = i + 2; j>=0 && k<top; J--, k++) {
if (!can (STRT[J].C, strt[k].c)) break;
}
}
if (S.lenth < k-j-1) {
S.st = Strt[j+1].pos;
S.ed = Strt[k-1].pos;
S.lenth = k-j-1;
}
}
cout<<s.lenth<<endl;
for (int i=s.st; i<=s.ed; i++)
cout<<str[i];
cout<<endl;
return 0;
}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Usaco section 1.3:calf Flac (CALFFLAC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.