题意:据说假设你给无限仅仅母牛和无限台巨型便携式电脑(有很大的键盘),那么母牛们会制造出世上最优秀的回文。

你的工作就是去寻找这些牛制造的奇观(最优秀的回文)。

在寻找回文时不用理睬那些标点符号、空格(但应该保留下来以便做为答案输出),仅仅用考虑字母'A'-'Z'和'a'-'z'。要你寻找的最长的回文的文章是一个不超过20,000个字符的字符串。 我们将保证最长的回文不会超过2,000个字符(在除去标点符号、空格之前)。

暴力 注意一些细节 输入字符中有回车啊之类的 wins下 输完按回车按Ctrl+z再按回车即可了

ubuntu下是Ctrl+z

代码:

#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{//副本

    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;

}

USACO Section 1.3 : Calf Flac (calfflac)的更多相关文章

  1. USACO 1.3.3 Calf Flac(Manacher算法)

    Description 据说如果你给无限只母牛和无限台巨型便携式电脑(有非常大的键盘),那么母牛们会制造出世上最棒的回文.你的工作就是去寻找这些牛制造的奇观(最棒的回文). 在寻找回文时不用理睬那些标 ...

  2. USACO 6.2 Calf Flac

    Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty la ...

  3. Calf Flac

    1.3.3 Calf Flac Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 223  Solved: 42[Submit][Status][Forum] ...

  4. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  5. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  6. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  7. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  8. USACO Section 5.3 Big Barn(dp)

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  9. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

随机推荐

  1. 10.2.0.4 to 10.2.0.5 Installation of Patch Set Release (Windows)

    环境:10.2.0.4集群数据库zlm10g(双节点,zlm10g1,zlm10g2) 系统:Windows 2003 Server 64Bit 内存:2G RAM 存储:ASM 目标:把集群数据库从 ...

  2. Pointcut is not well-formed: expecting 'name pattern' at character position 36

    Pointcut is not well-formed: expecting 'name pattern' at character position 36 学习了:http://blog.csdn. ...

  3. [CSS3] All abourt responsive image

    Take few examples: Full size image: The problem for that is it overflow when the screen size is smal ...

  4. C++链接和执行相关错误

    http://blog.csdn.net/pipisorry/article/details/37610401 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文 ...

  5. nmq 提交到 npm

    安装npm install nmq 源码:https://github.com/ronwe/nmq 此版本提供 pub/sub , 优化 pull

  6. ubuntu中taglist和ctags安装,简单明了

    1.使用命令安装ctags: sudo apt-get install ctags 2.安装taglist 下载: http://vim.sourceforge.net/scripts/downloa ...

  7. [NIO]dawn之Task具体解释

    在上篇文章中,我们设置好了开发环境,接下来.我们将在了解了Task以及Buffer之后,再開始了解网络编程.我们首先来看看Task task简单介绍 package zhmt.dawn; import ...

  8. poj_1952最大下降子序列,统计个数

    其实不算难的一道题,但憋了我好久,嗯,很爽. #include<iostream> #include<cstdio> #include<string.h> #inc ...

  9. js中console强大之处体现在哪

    js中console强大之处体现在哪 一.总结 一句话总结:在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对conso ...

  10. [JZOJ 5437] [NOIP2017提高A组集训10.31] Sequence 解题报告 (KMP)

    题目链接: http://172.16.0.132/senior/#main/show/5437 题目: 题解: 发现满足上述性质并且仅当A序列的子序列的差分序列与B序列的差分序列相同 于是我们把A变 ...