Hoj 1110 simply syntax // poj 1126 simply syntax

Source: Internet
Author: User

/*

 

Question:

The following three syntaxes are correct:

1. A single word, P to Z, uppercase letters: N, C, D, E, I

2. If the string S is correctly written, the NS is also correct.

3. If the string S, T is correct, then Cst, DST, EST, and ist are also correct.

 

Analysis:

Recursive string. If the length of the current string is 1, which complies with Syntax 1, the return value is correct. If the length is greater than 1,

If the current initial character is n and the recursion starts from the second digit, if the string is successful, return success. When the first letter is C, D, E, I,

If the string can be divided into three parts X (c, d, e, I), S, T, return success.

 

The string factorization function can use the substr function in the string, for example:

S = "12345"

S. substr( 1) = "2345 ";

S. substr (2) = "345 ";

 

*/

# Include <iostream>

# Include <string>

# Include <cstdio>

Using namespace STD;

Bool DFS (string S)

{

Int Len = S. Size ();

If (LEN = 1)

{

If (S [0]> = 'P' & S [0] <= 'Z ') | s [0] = 'n' | s [0] = 'C' | s [0] = 'D' | s [0] = = 'E' | s [0] = 'I ')

Return true;

Else

Return false;

}

If (s [0] = 'n ')

{

If (DFS (S. substr (1 )))

Return true;

Else

Return false;

}

If (s [0] = 'C' | s [0] = 'D' | s [0] = 'E' | s [0] = = 'I ')

{

If (LEN = 2)

Return false;

String temp;

For (INT I = 0; I <len-1; I ++)

{

Temp = temp + s [I];

If (DFS (temp. substr (1) & DFS (S. substr (I + 1 )))

Return true;

}

}

Return false;

}

Int main ()

{

Freopen ("sum. In", "r", stdin );

Freopen ("sum. Out", "W", stdout );

String S;

While (CIN> S)

{

If (DFS (s ))

Printf ("Yes \ n ");

Else

Printf ("NO \ n ");

}

Return 0;

}

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.