• Codeforces 1037A


    You are given a string ss, consisting of nn lowercase Latin letters.

    A substring of string ss is a continuous segment of letters from ss. For example, "defor" is a substring of "codeforces" and "fors" is not.

    The length of the substring is the number of letters in it.

    Let's call some string of length ndiverse if and only if there is no letter to appear strictly more than n2n2 times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.

    Your task is to find any diverse substring of string ss or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

    Input

    The first line contains a single integer nn (1n10001≤n≤1000) — the length of string ss.

    The second line is the string ss, consisting of exactly nn lowercase Latin letters.

    Output

    Print "NO" if there is no diverse substring in the string ss.

    Otherwise the first line should contain "YES". The second line should contain anydiverse substring of string ss.

    Examples

    Input
    10
    codeforces
    Output
    YES
    code
    Input
    5
    aaaaa
    Output
    NO

    Note

    The first example has lots of correct answers.

    Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

    题意:有大于1的连续子字符串,则输出YES,否则NO;并且随意输出一个子字符串。鉴于任意两个相邻且不同的字符,它们一定是子字符串,所以可以偷懒输出。

    #include <cstdio>
    #include <algorithm>
    #include <deque>
    #include <iostream>
    #include <string>
    #include <math.h>
     
    using namespace std;
     
    int n;
    string s;
     
    int main() {
        cin >> n >> s;
        char check = s[0];
        int len = s.length();
        bool flag = false;
        for (int i = 1;i < len;++i) {
            if (s[i] != check) {
                flag = true;
                break;
            }
        }
        if (flag) {
            cout << "YES" << endl;
            for (int i = 0;i < len - 1;++i) {
                if (s[i] != s[i + 1]) {
                    cout << s[i] << s[i + 1] << endl;
                    break;
                }
            }
        }
        else {
            cout << "NO" << endl;
        }
        //system("pause");
        return 0;
    }
  • 相关阅读:
    国内最火的3款前端开发框架
    Cordova是做什么的
    老师你好。使用cordova生成的hellowold 的安卓5.0版本太高。怎么才可以生成4.4的呢?
    一个类似bootstrap的foundation
    role在标签中的作用是什么?
    如何做到根据不同的进度用不同的颜色显示整个进度条
    wall 和panel有啥区别
    git ignore
    eclipse js 引用跳转
    计划
  • 原文地址:https://www.cnblogs.com/greenaway07/p/10419490.html
Copyright © 2020-2023  润新知