解题关键:KMP算法中NEXT数组的理解。

#include<bits/stdc++.h>
#define maxn 1000006
using namespace std;
typedef long long ll;
string s;
int Next[maxn];
bool vis[maxn];
void getNext(){
int i=,j=-;
Next[]=-;
while(i<s.size()){
if(j==-||s[i]==s[j]) Next[++i]=++j;
else j=Next[j];
}
for(int i=;i<s.size();i++) vis[Next[i]]=;
}
int main(){
cin>>s;
getNext();
int t=Next[s.size()];
bool flag=false;
while(t>){
if(vis[t]){
flag=;
for(int i=;i<t;i++) printf("%c",s[i]);
break;
}
t=Next[t];
}
if(!flag) printf("Just a legend\n");
return ;
}

[codeforces126B]Password的更多相关文章

  1. Codeforces126B - Password(KMP)

    题目大意 给定一个字符串S,要求你找到一个最长的子串,它既是S的前缀,也是S的后缀,并且在S的内部也出现过(非端点) 题解 KMP的失配函数f[i]的非零值就是前i个字符的一个最长前缀且也是后缀的字符 ...

  2. 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?

    p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...

  3. your password has expired.to log in you must change it

    今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...

  4. MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案

    关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...

  5. [上架] iOS "app-specific password" 上架问题

    当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...

  6. [LeetCode] Strong Password Checker 密码强度检查器

    A password is considered strong if below conditions are all met: It has at least 6 characters and at ...

  7. mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法

    MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...

  8. phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)

    phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...

  9. 保留password模式文本框textbox内的数据不丢失。

    在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号),就没有了! protected override ...

随机推荐

  1. Generator函数介绍

    Generator函数 基本概念 英文意思为 "生成器". generator函数是es6提供的一种异步编程解决方案,语法行为与传统函数完全不同.从状态上,首先我们把他理解成一种状 ...

  2. Element 'beans' cannot have character [children], because the type's content type is element-only

    这个小问题快搞死我了,找了大半个小时. Element 'beans' cannot have character [children], because the type's content typ ...

  3. 07-THREE.JS 各种形状的几何图形

    <!DOCTYPE html> <html> <head> <title>Example 02.04 - Geometries</title> ...

  4. jspm

    1.简介 JavaScript 模块的写法有几种,比如 AMD,CommonJS .. 还有标准化的 ES6 的写法 .. jspm 支持加载所有的用这些方法写的 JavaScript 模块 在你的应 ...

  5. 20180403_调bug_大地保险_jar包冲突

    一.异常现象 他们程序在本地通过java形式直接跑起来的时候,是正常的. 但是测试服务器上,程序跑到一半就不继续往下走了,而且,也不报错,日志里面没有任何信息. 二.异常解决 1.核心思想 抽丝剥茧, ...

  6. hive_异常_01_ Terminal initialization failed; falling back to unsupported

    一.异常现象 hive初始化数据库时,在执行了 schematool -initSchema -dbType mysql 这个命令时,终端抛出如下异常: [ray@rayner bin]$ schem ...

  7. git,npm,bower设置代理地址

    我們先假設代理伺服器的位址為: http://10.0.0.1:8080 設定 Git 使用代理伺服器 輸入兩行指令即可設定完畢: git config --global https.proxy ht ...

  8. 常用stl(c++)

    众所周知,c++的模板库是相当强大的. 下面我来列举一些常用的,(神奇的) //部分材料选自<算法竞赛入门经典(第2版)>(刘汝佳) 一,algorithm (算法) min(a,b)-- ...

  9. Boost 读写锁

    //#########测试多线程,读写锁,递归锁 #include <boost/thread.hpp> #include <boost/thread/recursive_mutex ...

  10. HDU - 5126 stars (CDQ分治)

    题目链接 题目大意:一共有Q(1<=Q<=50000)组操作,操作分为两种: 1.在x,y,z处添加一颗星星 2.询问以(x1,y1,z1)与(x2,y2,z2)为左上和右下顶点的矩形之间 ...