22771_Anyfoolcandoi

2022-5-16 18:22| 发布者: Hocassian| 查看: 37| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506943258500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22771

Title

Any fool can do it

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22771

AC

8

Submit

18

Ratio

44.44%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Surely you know someone who thinks he is very clever. You decide to let him down with the following problem:

    • "Can you tell me what the syntax for a set is?", you ask him.

    • "Sure!", he replies, "a set encloses a possibly empty list of elements within two curly braces. Each element is either another set or a letter of the given alphabet. Elements in a list are separated by a comma."

    • "So if I give you a word, can you tell me if it is a syntactically correct representation of a set?"

    • "Of course, any fool can do it!" is his answer.

    Now you got him! You present him with the following grammar, defining formally the syntax for a set (which was described informally by him):

    Set          ::= "{" Elementlist "}"
    Elementlist  ::= <empty>  |  List
    List         ::= Element  |  Element "," List
    Element      ::= Atom  |  Set
    Atom         ::= "{"  |  "}"  |  ","

    <empty> stands for the empty word, i.e., the list in a set can be empty.

    Soon he realizes that this task is much harder than he has thought, since the alphabet consists of the characters which are also used for the syntax of the set. So he claims that it is not possible to decide efficiently if a word consisting of "{", "}" and "," is a syntactically correct representation of a set or not.

    To disprove him, you need to write an efficient program that will decide this problem.

    输入

    The first line of the input contains a number representing the number of lines to follow.

    Each line consists of a word, for which your program has to decide if it is a syntactically correct representation of a set. You may assume that each word consists of between 1 and 200 characters from the set { "{", "}", "," }.

    输出

    Description

    Surely you know someone who thinks he is very clever. You decide to let him down with the following problem:

    • "Can you tell me what the syntax for a set is?", you ask him.

    • "Sure!", he replies, "a set encloses a possibly empty list of elements within two curly braces. Each element is either another set or a letter of the given alphabet. Elements in a list are separated by a comma."

    • "So if I give you a word, can you tell me if it is a syntactically correct representation of a set?"

    • "Of course, any fool can do it!" is his answer.

    Now you got him! You present him with the following grammar, defining formally the syntax for a set (which was described informally by him):

    Set          ::= "{" Elementlist "}"
    Elementlist  ::= <empty>  |  List
    List         ::= Element  |  Element "," List
    Element      ::= Atom  |  Set
    Atom         ::= "{"  |  "}"  |  ","

    <empty> stands for the empty word, i.e., the list in a set can be empty.

    Soon he realizes that this task is much harder than he has thought, since the alphabet consists of the characters which are also used for the syntax of the set. So he claims that it is not possible to decide efficiently if a word consisting of "{", "}" and "," is a syntactically correct representation of a set or not.

    To disprove him, you need to write an efficient program that will decide this problem.

    Input

    The first line of the input contains a number representing the number of lines to follow.

    Each line consists of a word, for which your program has to decide if it is a syntactically correct representation of a set. You may assume that each word consists of between 1 and 200 characters from the set { "{", "}", "," }.

    Output

    Output for each test case whether the word is a set or not. Adhere to the format shown in the sample output.

    Sample Input

    4
    {}
    {{}}
    {{}},{,}}
    {,,}

    Sample Output

    Word #1: Set
    Word #2: Set
    Word #3: Set
    Word #4: No Set

    Source

    样例输入

    4
    {}
    {{}}
    {{}},{,}}
    {,,}

    样例输出

    Word #1: Set
    Word #2: Set
    Word #3: Set
    Word #4: No Set

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部