HDU 5311 Hidden String (elegant brute force), hdu5311

Source: Internet
Author: User

HDU 5311 Hidden String (elegant brute force), hdu5311


Hidden String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission (s): 52 Accepted Submission (s): 25


Problem DescriptionToday 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. 1 ≤ l1 ≤ r1 <l2 ≤ r2 <l3 ≤ r3 ≤ n

2. The concatenation 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 (1 ≤ T ≤100) , 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
2annivddfdersewwefarynniversarya
Sample Output
YESNO
Source BestCoder 1st Anniversary ($)
Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 5311

Question: In a string, we cannot find three consecutive intervals and splice them into anniversary.

Question Analysis: brute force, enumerative length of each segment

#include <cstdio>#include <cstring>char s[200], con[] = "anniversary";int main(){    int T;    scanf("%d", &T);    while(T--)    {        scanf("%s", s);        int len = strlen(s);        bool flag = false;        for(int i = 0; i <= 8; i++)        {            for(int j = i + 1; j <= 9; j++)            {                int k = 0;                while(k < len && strncmp(con, s + k, i + 1) != 0)                    k ++;                if(k == len)                     continue;                k += i + 1;                while(k < len && strncmp(con + i + 1, s + k, j - i) != 0)                    k ++;                if(k == len)                     continue;                k += j - i;                while(k < len && strncmp(con + j + 1, s + k, 10 - j) != 0)                    k ++;                if(k != len)                {                    flag = true;                    break;                }            }        }        if(flag)             puts("YES");        else             puts("NO");    }}




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.