A - Password

Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix

Output

fix

Input

abcdabc

Output

Just a legend

题意:给定一个字符串,求他的最长的子串,使得其同时是原字符串的前缀、后缀,并且去原字符串掉第一个和最后一个字母后,该子串仍然存在。无解输出“Just a legend”。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
typedef unsigned long long ull;
const int m = 10000010;
const int p = 163;
char mapp[m];
ull hashh[m], idx[m];
int n, flag[m];
int main()
{
    while(scanf("%s", mapp+1)!=EOF)
    {

        //hash的常规操作;
        int len = strlen(mapp+1);
        idx[0] = 1;
        hashh[0] = 0;
        for(int i=1; i<=len; i++)
        {
            idx[i] = idx[i-1]*p;
            hashh[i] = hashh[i-1]*p+mapp[i];
        }


        flag[1] = flag[2] = 1;
        //flag[i]数组用来记录在第i个字符前除去与其相同的后缀外,存在第二个的 最长子串的长度;
        for(int i=2; i<=len; i++)
        {
            int j = flag[i];
            while(j>1&&mapp[i]!=mapp[j])
                j = flag[j];
            if(mapp[i]== mapp[j])
                flag[i+1]=j+1;
            else
                flag[i+1]=1;
        }

        int p = 0;
        for(int i=1; i<=len; i++)
        {
            int l = flag[i]-1;
            //判断该字符串是否还存在(在除去相同后缀外),并且判断是否有相同的后缀;
            if(l>p && hashh[l]==hashh[len]-hashh[len-l]*idx[l])
                p = l;
        }
        if(p>0)
        {
            mapp[p+1] = '\0';
            printf("%s\n", mapp+1);
        }
        else
            printf("Just a legend\n");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个包含三个密码输入框的表单,分别是“当前密码”、“新密码”和“确认密码”。其中,“新密码”和“确认密码”输入框使用了`pattern`属性,规定了密码的最小长度为6位,并给出相应的提示信息。此外,“当前密码”输入框使用了`required`属性,表示该输入框必须填写才能提交表单。 如果要修改为必须有大小写字母加特殊字符组成,且不小于8位,则可以将代码修改为: ```html <form> <div class="form-group"> <label for="current-password">当前密码</label> <input type="password" class="form-control" id="current-password" name="current-password" placeholder="请输入当前密码" required> <div class="invalid-feedback">请输入当前密码</div> </div> <div class="form-group"> <label for="new-password">新密码</label> <input type="password" class="form-control" id="new-password" name="new-password" placeholder="请输入新密码" required oninput="checkNewPassword()"> <span id="new-password-tip" style="color:red;"></span> </div> <div class="form-group"> <label for="confirm-password">确认密码</label> <input type="password" class="form-control" id="confirm-password" name="confirm-password" placeholder="请再次输入新密码" required oninput="checkConfirmPassword()"> <span id="confirm-password-tip" style="color:red;"></span> </div> <button type="submit" class="btn btn-primary">确认修改</button> </form> <script> function checkNewPassword() { const password = document.getElementById('new-password').value; const regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]).{8,}$/; const isValid = regex.test(password); const tip = document.getElementById('new-password-tip'); if (isValid) { tip.innerHTML = ''; } else { tip.innerHTML = '密码必须包含大小写字母、数字和特殊字符,并且长度不小于8位'; } } function checkConfirmPassword() { const password = document.getElementById('new-password').value; const confirmPassword = document.getElementById('confirm-password').value; const tip = document.getElementById('confirm-password-tip'); if (password === confirmPassword) { tip.innerHTML = ''; } else { tip.innerHTML = '两次输入的密码不相同'; } } </script> ``` 这段代码与之前的代码相比,主要是对“新密码”和“确认密码”输入框的校验逻辑进行了修改。在输入框中添加了`oninput`事件,当用户输入密码时,会自动调用`checkNewPassword`和`checkConfirmPassword`函数进行校验。`checkNewPassword`函数的逻辑与前面的前端表单中的校验逻辑相同,都是使用正则表达式判断密码是否符合要求,并在提示信息中显示具体的错误信息。`checkConfirmPassword`函数则用于判断两次输入的密码是否相同,并在提示信息中显示错误信息。 这样修改后,用户必须输入符合要求的新密码才能修改密码,并且两次输入的密码必须相同才能提交表单。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值