HDU5311 Hidden String

Problem Description
  Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string  s of length n. He wants to find three nonoverlapping substrings s[l1..r1]s[l2..r2]s[l3..r3] that:

1. 1l1r1<l2r2<l3r3n

2. The concatenation of s[l1..r1]s[l2..r2]s[l3..r3] is "anniversary".
 
Input
There are multiple test cases. The first line of input contains an integer  T (1T100), indicating the number of test cases. For each test case:
There's a line containing a string s (1|s|100) consisting of lowercase English letters.
 
Output
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
 

Sample Input

2
annivddfdersewwefary
nniversarya
 
Sample Output
YES
NO
 

 我觉得我写的好无脑

#include<iostream>

#include<string>

using namespace std;

string s("anniversary");

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		string ss;

		cin>>ss;

		int a,b,c,f=1;

		for(int i=0;i<9;i++)

		{

			if(f)		

			for(int j=i+1;j<10;j++)	

			{

				string s1(s,0,i+1);

				string s2(s,i+1,(j-i));

				string s3(s,j+1,(10-j));

				a=ss.find(s1);

				b=ss.find(s2,a+s1.size());

				c=ss.find(s3,b+s2.size());

				if(a!=-1&&b!=-1&&c!=-1)

				{

					cout<<"YES"<<endl;

					f=0;break;

				}

			}

			else break;

	   }

		if(f)

		cout<<"NO"<<endl;

	}

	return 0;

} 

  

你可能感兴趣的:(String)