zoukankan      html  css  js  c++  java
  • 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;
    } 
    

      

  • 相关阅读:
    samba安装和配置
    linux下打包命令的使用
    Linux目录结构简析
    Linux服务器的安装
    linux下定时任务设置
    创建表空间并授权
    selenium2.0(WebDriver) API
    selenium + python之元素定位
    Linux实战教学笔记13:定时任务补充
    Linux实战教学笔记11:linux定时任务
  • 原文地址:https://www.cnblogs.com/duanyuanzhi/p/4676918.html
Copyright © 2011-2022 走看看