AtCoder Beginner Contest 066 B - ss
题目链接: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 xyzxy
are 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
abaababaab
Sample Output 1
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
xxxx
Sample Output 2
2
xxx
is not even.xx
is even.
Sample Input 3
abcabcabcabc
Sample Output 3
6
The longest even string that can be obtained is abcabc
, whose length is 6.
Sample Input 4
akasakaakasakasakaakas
Sample Output 4
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的更多相关文章
- AtCoder Beginner Contest 254(D-E)
Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
随机推荐
- FCN-全卷积网络
全卷积网络 Fully Convolutional Networks CNN 与 FCN 通常CNN网络在卷积层之后会接上若干个全连接层, 将卷积层产生的特征图(feature map)映射成一个固定 ...
- vue 本地静态图片路径写法
在img标签中 <img src="../../assets/images/haibao/06-2@2x.png" class="" width=&quo ...
- ionic 版本内更新问题汇总
1.签名不一致导致的更新失败 2.解析软件包出现问题 3.当文件下载完.在android 8.0中不能打开apk包的问题 解决方案:在config.xml中添加: <platform name= ...
- windows go dll 框架
乘着还没有添加商业功能之前,先给大家把福利分享了 希望有需要的朋友能够用的上 这个框架是在用windows平台,GO做的http/https服务,调用dll现有的库接口实现特定功能的大框架 //dll ...
- (转载)Windows WMIC命令使用详解(附实例)
原文地址:http://www.jb51.net/article/49987.htm 第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符.在WMIC命令行提示 ...
- Amber learning note A8: Loop Dynamics of the HIV-1 Integrase Core Domain
1. Prepare Input File $ tleap >source leaprc.protein.ff14SB ----- Source: /home/wangq/Programs/am ...
- cocosStudio制作ScrollView并在cocos2dx 3.0中使用。
使用cocosStudio制作界面基本已成为基础了,之前都是拖动一些 Image.Button的小控件,再用到层容器和滚动层的时候,习惯性的用拖动来改变控件的大小.但是你在把其他的控件拖动到上面的时候 ...
- Python基础(四) socket简单通讯
socket:我们通常听过的套接字: 服务端: 1.创建socket对象 2.bing 绑定ip及端口 3.对该端口进行监听 4.消息阻塞(等待客户端消息) 客户端: 1.创建socket对象 2.连 ...
- 「美团外卖APP签约快捷支付」流程体验
§1 添加银行卡 新用户在美团外卖APP订餐支付时,首先要绑定银行卡.如下是“添加银行卡”页,输入卡号后,系统自动调用卡bin库校验卡号的有效性,如果有效会显示发卡行和卡类型(借记卡/贷记卡). 这 ...
- shell基础:1.1脚本执行方式
echo 后边跟的东西有空格,那么需要加上单引号或双引号.!是有特殊含义的,用单引号原意. 尽管linux不区分文件的后缀,但还是要写上以便于区分. #!Bash 这行不是注释,也不能省略,他的 ...