题目1 : Beautiful String
-
4 3 abc 4 aaab 6 abccde 3 abb
样例输出
-
YES NO YES
NO
-
#include <iostream> #include <string> using namespace std; int main(){ int n; long long k; string s; cin >> n; while(n--){ cin >> k >> s; for(int i = 0; i < k; ++i){ if(i == k -1){ cout << "NO" << endl; break; } int count = 1; bool flag = true; for(int j = i + 1; j < k; ++j){ if(s[j] == s[i]) count++; else break; } if(k < i + 3*count){ continue; } for(int p = i + count; p <= i+2*count-1; ++p){ if(s[p] != s[i] + 1){ flag = false; break; } } if(!flag) continue; for(int q = i+2*count; q <= i + 3*count -1; ++q){ if(s[q] != s[i] + 2){ flag = false; break; } } if(flag){ cout << "YES" << endl; break; } else{ continue; } } } return 0; }
描述
We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.)
Here are some example of valid beautiful strings: "abc", "cde", "aabbcc", "aaabbbccc".
Here are some example of invalid beautiful strings: "abd", "cba", "aabbc", "zab".
Given a string of alphabets containing only lowercase alphabets (a-z), output "YES" if the string contains a beautiful sub-string, otherwise output "NO".
输入
The first line contains an integer number between 1 and 10, indicating how many test cases are followed.
For each test case: First line is the number of letters in the string; Second line is the string. String length is less than 10MB.
输出
For each test case, output a single line "YES"/"NO" to tell if the string contains a beautiful sub-string.
提示
Huge input. Slow IO method such as Scanner in Java may get TLE.