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

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

在寻找回文时不用理睬那些标点符号、空格(但应该保留下来以便做为答案输出),仅仅用考虑字母'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;

}

最新文章

  1. avascript中的this与函数讲解
  2. 在SQL Server里为什么我们需要更新锁
  3. BZOJ 1143 1143: [CTSC2008]祭祀river 最长反链
  4. Android开发之实用小知识点汇总-1
  5. POJ-1200(哈希)
  6. JOSM学习下载地址
  7. CodeForces 276D – Little Girl and Maximum XOR 贪心
  8. LeetCode 395. Longest Substring with At Least K Repeating Characters C#
  9. 【转】Flash字体嵌入方法
  10. Linux改变语言设置的命令
  11. Docker在Linux上运行NetCore系列(三)在Linux上使用Docker运行Asp.NetCore
  12. (十) 编写UVC程序
  13. MySQL 执行计划中Extra(Using where,Using index,Using index condition,Using index,Using where)的浅析
  14. laravel项目使用appnode部署linux系统到阿里云服务器流程记录(待补充)
  15. 全文搜索引擎——Solr
  16. nginx上传文件时 nginx 413 Request Entity Too Large 错误
  17. vs2010下release版本调试设置
  18. 洛谷P4587 神秘数 [FJOI2016] 主席树
  19. python 虚拟环境操作 virtualenv +virtualenvwrapper
  20. Android的GridView控件点击图片变暗效果

热门文章

  1. vim 跳转指定行
  2. 设计模式实例(Lua)笔记之七(Decorator模式)
  3. jdk1.8Option类
  4. [Struts2] No result defined for action ... and result input &amp;amp; Invalid field value for field ...
  5. c# 获取一年中的周/根据一年中的第几周获取该周的开始日期与结束日期
  6. BZOJ 3112 [Zjoi2013]防守战线 线性规划
  7. Mysqldump逻辑备份与恢复
  8. 在ubuntu下访问windows硬盘出现错误:Error mounting /dev/sda7 at /media
  9. Android View 上下左右四种间距的设置方法
  10. Android 广播大全 Intent Action 事件详解