ACM-ICPC International College Student Program Design Competition Beijing (2015) network practice title 4:beautiful String

Source: Internet
Author: User

We say a string is beautiful if it have the equal amount of 3 or more continuous letters (in increasing order.)

Here is some example of valid beautiful strings: "abc", "CDE", "AABBCC", "AAABBBCCC".

Here is 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".

Input

The first line contains an integer number between 1 and ten, indicating how many test cases is followed.

For each test Case:first the number of letters in the string; Second is the string. String length is less than 10MB.

Output

For each test case, output A, "YES" or "NO" to-tell if the string contains a beautiful sub-string.

Tips

Huge input. Slow IO method such as Scanner in Java may get TLE.

Sample input

43abc4aaab6abccde3abb

Sample output

Yesnoyesno

1#include <iostream>2#include <vector>3#include <string>4 using  namespacestd;5 6 intMain () {7     intN;8Cin>>N;9      while(n-- ) {Tenvector<Char>v; One         intnum; ACin>>num; -         stringstr; -Cin>>str; thevector<Char>v1; -vector<int>v2; -V1.push_back (str[0]); -V2.push_back (1); +         intFlag =1; -      +          for(inti =1; I < str.size (); i++ ) { A             if(Str[i] = = str[i-1] ) { at                 inttemp = * (V2.end ()-1); -temp++; - V2.pop_back (); - V2.push_back (temp); -                 if(v2[1] = = v2[2] && v2[0] >= v2[1] && v1[2]-v1[1] ==1&& v1[1]-v1[0] ==1) { -cout<<"YES"<<Endl; inFlag =0; -                          Break; to                     } +             } -             Else { the                 if(V1.size () <3 ) { * V1.push_back (Str[i]); $V2.push_back (1);Panax Notoginseng                     if(v2[1] = = v2[2] && v2[0] >= v2[1] && v1[2]-v1[1] ==1&& v1[1]-v1[0] ==1) { -cout<<"YES"<<Endl; theFlag =0; +                          Break; A                     } the                 } +                 Else {                     - v1.erase (V1.begin ()); $ v2.erase (V2.begin ()); $ V1.push_back (Str[i]); -V2.push_back (1); -                         if(v2[1] = = v2[2] && v2[0] >= v2[1] && v1[2]-v1[1] ==1&& v1[1]-v1[0] ==1) { thecout<<"YES"<<Endl; -Flag =0;Wuyi                          Break; the                     } -                      Wu                 } -             } About         }     $         if(flag) -cout<<"NO"<<Endl;  -     } -     return 0; A}

ACM-ICPC International College Student Program Design Competition Beijing (2015) network practice title 4:beautiful String

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.