uestc_in galgame We Trust cdoj 10

Source: Internet
Author: User

As we all know, there is many interesting (H) games in Kennethsnow ' s computer. But he sets a password for the those games. Zplinti1 wants to crack he password and play those games.

Kennethsnow uses only 6 kinds of characters to form his password:

    1. Brackets: and ()
    2. Square brackets: and []
    3. Curly brackets: and {}

Kennethsnow ' s password must be a correct bracket sequence, and won't be empty.

Zplinti1 found a string written by Kennethsnow, and he's sure that Kennethsnow's password is a substring of that, he wond ERS the maximum possible length of his password, or if he judgment is wrong.

Please note this original string may also is the password.

Input

The first line of input contains a numberT, indicating the number of test cases. (T≤ There is a string s, which is the string zplinti1 found. (1≤| S| ≤1,the The string would contain those 6 kinds of characters only)

Output

For each case, outputCase #i:First. (IIs the number of the "Test case" from 1 to T). If Zplinti1 ' s judgment is wrong (i.e. the answer are 0), output I think H is wrong! , otherwise output a single number, I Ndicating the maximum possible length of Kennethsnow ' s password.

Sample Input and output

Sample Input Sample Output
3 () {[]}{([(])})] [{}]]
Case #1:6Case #2: I think H is wrong! Case #3:4
Hint

We can define a more precisely in the this by correct bracket sequence :

Strings () , [] and is {} correct.

For each correct sequence A , (A) , [A] is {A} also correct.

For each correct sequence A B and, is AB also correct.

Problem Solving Report:

Stack of simple application questions ~, from left to right sweep again, belong to the legal sequence of flag flag, and then sweep again, to confirm the longest continuous legal length

#include <iostream>#include<algorithm>#include<cstring>Const intMAXN =1000000+ -;using namespacestd;CharS[MAXN];intPOS[MAXN];BOOLFLAG[MAXN];BOOLMatchCharS1,CharS2) {  if(S1 = ='('&& S2! =')')   return false; Else if(S1 = ='['&& S2! =']')   return false; Else if(S1 = ='{'&& S2! ='}')   return false; return true;}intMainintARGC,Char*argv[]) {  intcase,t=1; scanf ("%d",&Case );  while(case--) {scanf ("%s", s); inttop =0, ans =0, Len = strlen (s), pt =0; memset (Flag,false,sizeof(flag));  for(inti =0; i < Len; ++i) {if(S[i] = ='('|| S[i] = ='['|| S[i] = ='{') Pos[top++] =i; Else if(Top >0)                 {                       intTPOs = pos[--top]; CharTS =S[tpos]; if(Match (Ts,s[i])) {Flag[tpos]=true; Flag[i]=true; }              ElseTop=0; }       }       for(inti =0; i < Len; ++i)if(!Flag[i]) {ans=Max (ANS,PT); PT=0; }       ElsePT++; Ans=Max (ANS,PT); printf ("Case #%d:", t++); if(ANS) printf ("%d\n", ans); Elseprintf ("I think H is wrong!\n"); }  return 0;}

uestc_in galgame We Trust cdoj 10

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.