解题关键: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. tsne pca 自编码器 绘图(CC2)——一定记得做无量纲化处理使用standardscaler,数据聚类更明显

    tsne 数据不做预处理: # coding: utf-8 import collections import numpy as np import os import pickle from skl ...

  2. LeetCode OJ:Contains DuplicateII(是否包含重复II)

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  3. How to install php 7.x on CentOS 7

    Step 1: Setup the Webtatic YUM repo Precompiled PHP 7.x binaries are available for CentOS 7 from the ...

  4. Sortable

    d_(:з」∠)_ import React, {Component} from 'react'; import "./app.css"; import Sortable from ...

  5. 总结的一些MySQL数据库面试题

    1.sql语句应该考虑哪些安全性? 1.防止sql注入,对特殊字符进行转义,过滤或者使用预编译的sql语句绑定变量. 2.最小权限原则,特别是不要用root账户,为不同的类型的动作或者组建使用不同的账 ...

  6. pandas中Loc vs. iloc vs. ix vs. at vs. iat?

    loc: only work on indexiloc: work on positionix: You can get data from dataframe without it being in ...

  7. MMS(mongodb监控工具)

    今天好几个人问我如何查看mongodb的连接数,在mongo shell中执行: shard1:PRIMARY> db.serverStatus().connections { "cu ...

  8. 在Linux上利用core dump和GDB调试segfault

    时常会遇到段错误(segfault),调试非常费劲,除了单元测试和基本测试外,有些时候是在在线环境下,没有基本开发和测试工具,这就需要调试的技能.以前介绍过使用strace进行系统调试和追踪<l ...

  9. 使用PowerShell在Azure China创建Data Warehouse

    微软的Azure Data Warehouse是基于MPP架构的分布式系统: Control Node负责管理系统和接受用户的请求,Compute Node负责计算. 目前在国内Azure Data ...

  10. 蓝桥杯 历届试题 PREV-32 分糖果

    历届试题 分糖果   时间限制:1.0s   内存限制:256.0MB 问题描述 有n个小朋友围坐成一圈.老师给每个小朋友随机发偶数个糖果,然后进行下面的游戏: 每个小朋友都把自己的糖果分一半给左手边 ...