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 nn diverse 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 (1≤n≤10001≤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
10
codeforces
YES
code
5
aaaaa
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; }