题目链接:http://abc066.contest.atcoder.jp/tasks/abc066_b

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxyare not.

You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Constraints

  • 2≤|S|≤200
  • S is an even string consisting of lowercase English letters.
  • There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the length of the longest even string that can be obtained.


Sample Input 1

Copy
abaababaab

Sample Output 1

Copy
6
  • abaababaab itself is even, but we need to delete at least one character.
  • abaababaa is not even.
  • abaababa is not even.
  • abaabab is not even.
  • abaaba is even. Thus, we should print its length, 6.

Sample Input 2

Copy
xxxx

Sample Output 2

Copy
2
  • xxx is not even.
  • xx is even.

Sample Input 3

Copy
abcabcabcabc

Sample Output 3

Copy
6

The longest even string that can be obtained is abcabc, whose length is 6.


Sample Input 4

Copy
akasakaakasakasakaakas

Sample Output 4

Copy
14

The longest even string that can be obtained is akasakaakasaka, whose length is 14.

题解:还是比较有趣 如果前一半字符和后一半字符一样就输出总字符数 否则字符串尾删除一个字符

   那就用栈吧 不满足的话就用栈删除很方便

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+; int main()
{
std::ios::sync_with_stdio(false);
char a[];
scanf("%s",a);
stack<char> s;
int len=strlen(a);
for(int i=;i<len;i++)
s.push(a[i]);
s.pop();
int t,flag;
while(){
if(s.size()%==) s.pop();
else {
t=s.size();
t/=;
flag=;
for(int i=;i<t;i++){
if(a[i]!=a[i+t]){
flag=;
break;
}
}
if(flag){
cout<<t*<<endl;
break;
}
else s.pop();
}
}
return ;
}

AtCoder Beginner Contest 066 B - ss的更多相关文章

  1. AtCoder Beginner Contest 254(D-E)

    Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  4. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  5. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  6. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  7. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  8. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  9. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

随机推荐

  1. MongoDB pymongo模块

    安装pymongo模块 pip install pymongo 连接mongodb代码,生成pymongo对象,传入连接服务器相关参数 ip 端口 如果使用指定的账户登录,设置要登录的账户和密码,然后 ...

  2. weixin.com的whois信息变更为腾讯了 是准备替换weixin.qq.com吗?

    微信双拼域名weixin.com的whois信息变更,所有人为腾讯.从weixin.com在10月18日这次的whois变更上,透露出腾讯似乎准备启用这个域名.如果启用,毋庸置疑是要应用在腾讯的巨无霸 ...

  3. 微信小程序可以转发给微信好友了

    微信小程序又放大招了:小程序页面可以放置转发按钮,分享更流畅.同时开放了微信运动步数.背景音乐播放等更多基础能力.小程序可以在自己的页面上放置转发按钮,用户点击后,即可将喜欢的内容分享给好友或群聊,体 ...

  4. 使用shell脚本监控用户登陆服务器并发送提示信息给微信

    1.需要在/etc/ssh/目录下面创建一个名为sshrc的文件,执行权限可给可不给,那么在有人通过ssh远程登录这台服务器的时候,这段脚本就会被执行 #!/bin/bash ###V1---### ...

  5. Python3学习之路~8.3 socket 服务端与客户端

    通过8.2的实例1-6,我们可以总结出来,socket的服务端和客户端的一般建立步骤: 服务端 步骤:1创建实例,2绑定,3监听,4阻塞,5发送&接收数据,6关闭. #Author:Zheng ...

  6. react 首屏加载优化

    react 首屏加载优化,原本是在入口HTML文件中加载loading动画,但是部署在测试环境上的时候一直无法显示loading的部分,也是奇怪了,我们测试环境的部署一直跟本地的都不太一样,内外网的转 ...

  7. cookie、session和token

    https://zhuanlan.zhihu.com/p/25495290?utm_source=wechat_session&utm_medium=social 一.cookie 众所周知, ...

  8. 用python 替换文件中的git地址

    有个需求要替换文件中git地址,要替换成的git地址是一个变量 本来想用sed替换但是git地址中有斜杠符号 需要转义,提前知道还好弄,如果是变量就不好处理了 #!/usr/bin/python3 # ...

  9. Graphviz

    不能显示中文,我的处理方法是: node [shape = box,fontname =“Microsoft YaHei”] edge [fontname =“Microsoft YaHei”] 似乎 ...

  10. vmware相关设置

    vmware虚拟机和宿主机共享文件夹 点击“虚拟机”->“设置” 进入之后,选择“选项”选项卡->选择“共享文件夹”(此处已启用实在安装VMware Tools时选择了启用共享文件夹功能) ...