• 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;
    }
  • 相关阅读:
    TestNG系列(四)TestNG监听器
    SpringBoot中Conditional的条件
    TCP的四次挥手与三次握手
    [Lamada] lamda流操作
    [Spring] 封装request 自定义添加parameter
    AES加密Demo
    [转]数据库软件架构,到底要设计些什么
    [正则表达式]
    [mysql] 查询配置文件读取位置和顺序
    [MySQL]错误日志
  • 原文地址:https://www.cnblogs.com/greenaway07/p/10419490.html
Copyright © 2020-2023  润新知