当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2475:Any fool can do it

题目描述
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 { "{", "}", "," }.
输出解释
Output for each test case whether the word is a set or not. Adhere to the format shown in the sample output.
输入样例
4
{}
{{}}
{{}},{,}}
{,,}
输出样例
Word #1: Set
Word #2: Set
Word #3: Set
Word #4: No Set

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Ulm Local 2005

源链接: POJ-2475

最后修改于 2020-10-29T06:33:34+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536