1185 : 逻辑表达式的可满足性
时间限制Time Limit
1
秒Sec
内存限制Memory Limit
128
兆MB
提交次数Submitted
14 次Times
通过次数Solved
5 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
逻辑表达式有如下形式: 1. 原子式,用一个区分大小写的字母表示; 2. 组合式;若 A 和 B 是逻辑表达式,则(A|B)也是,意为“A或B”; (A&B)意为“A和B”;
~A 意为“非A”; (A->B)意为“A推出B”,或等价的“B或非A”。
以上表达式的形式是固定的,其中的括号不能缺少,且字符间没有空格。
对于某个逻辑表达式,如果变换其中原子式的取值(真或假),该表达式的整体取值可能为真,则称这样的逻辑表达式是可满足的,否则是不可满足的。比如下面的表达式都是可满足的:
q
(a|(b&c))
((a&~a)->z)而这些是不可满足的:
(q&~q)
(((a|~b)&(~a|b))&(a&~b))编写程序,判断某个逻辑表达式的可满足性。
输入格式Input
不超过500组数据,每组数据一行,是一个逻辑表达式,每个表达式最多 10 个原子式,且不超过 150 个字符。没有空行,也没有空格。
输出格式Output
每行包含一个字符,’y’表示输入文件对应行中的逻辑表达式是可满足的,或者‘n’表示输入文件对应行中的逻辑表达式是不可满足的。