poj 1126 Simply Syntax

来源:互联网 发布:淘宝怎么充钱余额 编辑:程序博客网 时间:2024/05/24 06:42

题意:这道题目是与语法规则有关的,首先这些语法规则满足下面的条件:

0.The only characters in the language are the characters p through z and N, C, D, E, and I.

1.Every character from p through z is a correct sentence. //只有p到z的语法正确

2.If s is a correct sentence, then so is Ns. //若s语法正确那么Ns语言也正确

3.If s and t are correct sentences, then so are Cst, Dst, Est and Ist.//若s和t语法正确, Cst, Dst, Est, Ist语法也正确
题目输入了一些数据,问这些数据是否满足了语法规则。

题目思路:显然无论怎么样该语法的最后一个字符一定是p到z之间,所以我们可以反转这个数据,然后再进行判断。

思路来源:discuss,很不错的一个想法。

代码: