題意:這道題目是與語法規則有關的,首先這些語法規則滿足下面的條件:
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,很不錯的一個想法。
代碼: