poj 1126 Simply Syntax (反向枚举)
来源:互联网 发布:linux ntp 同步命令 编辑:程序博客网 时间:2024/05/16 06:45
Simply Syntax
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5552 Accepted: 2482
Description
In the land of Hedonia the official language is Hedonian. A Hedonian professor had noticed that many of her students still did not master the syntax of Hedonian well. Tired of correcting the many syntactical mistakes, she decided to challenge the students and asked them to write a program that could check the syntactical correctness of any sentence they wrote. Similar to the nature of Hedonians, the syntax of Hedonian is also pleasantly simple. Here are the rules:
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.
2.If s is a correct sentence, then so is Ns.
3.If s and t are correct sentences, then so are Cst, Dst, Est and Ist.
4.Rules 0. to 3. are the only rules to determine the syntactical correctness of a sentence.
You are asked to write a program that checks if sentences satisfy the syntax rules given in Rule 0. - Rule 4.
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.
2.If s is a correct sentence, then so is Ns.
3.If s and t are correct sentences, then so are Cst, Dst, Est and Ist.
4.Rules 0. to 3. are the only rules to determine the syntactical correctness of a sentence.
You are asked to write a program that checks if sentences satisfy the syntax rules given in Rule 0. - Rule 4.
Input
The input consists of a number of sentences consisting only of characters p through z and N, C, D, E, and I. Each sentence is ended by a new-line character. The collection of sentences is terminated by the end-of-file character. If necessary, you may assume that each sentence has at most 256 characters and at least 1 character.
Output
The output consists of the answers YES for each well-formed sentence and NO for each not-well-formed sentence. The answers are given in the same order as the sentences. Each answer is followed by a new-line character, and the list of answers is followed by an end-of-file character.
Sample Input
CpIszNIszCqpq
Sample Output
NOYESYESNO
反过来考虑,每个字母可以算一句话,最后组成的只是一句话
#include <iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char str[300]; int flag; while(~scanf("%s",str)) { int len=strlen(str); int cnt=0; for(int i=len-1;i>=0;i--) { if(str[i]>='p'&&str[i]<='z') { cnt++; } else if(str[i]=='N') { if(cnt==0) { break; } } else if(str[i]=='C'||str[i]=='D'||str[i]=='E'||str[i]=='I') { if(cnt>=2) { cnt--; } else { cnt=0; break; } } else { cnt=0; break; } } if(cnt==1)//最后只能成为一句话 printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- poj 1126 Simply Syntax (反向枚举)
- poj 1126 Simply Syntax
- POJ 1126 Simply Syntax
- POJ 1126:Simply Syntax
- POJ 1126 Simply Syntax 笔记
- POJ:1126 Simply Syntax(思维)
- poj 1126 Simply Syntax 右线性文法的归约
- POJ-1126——Simply Syntax (暴力扫一遍)
- Hdu 1433 Simply Syntax【dfs枚举】
- POJ1126 Simply Syntax (递归)
- HDOJ 1433 Simply Syntax
- Hdoj 1433 Simply Syntax 【string】
- hdoj Simply Syntax 1433 (模拟)
- hdoj 1433 Simply Syntax【模拟】
- POJ 1126 Simple Syntax
- hdoj.1433 Simply Syntax【递归调用】 2015/04/24
- POJ 2022 Syntax Included 笔记
- Myeclipse反向工程后造成的SQL syntax
- Leetcode刷题
- 操作系统概念第七版-第一章导论
- Android中的Shape使用总结
- java初学类于对象
- POJ解题报告——1002 487-3279
- poj 1126 Simply Syntax (反向枚举)
- 链表倒数第n个数
- 2017广东工业大学程序设计竞赛决赛总结
- 【Oracle学习】之 数据库创建
- Caffe源码解读(二):caffe.proto(下)
- Floyd-Warshall算法模板
- 灰度投影法和余弦定理用于阵列图像分类
- 慕课网学习笔记----《网页布局基础》—绝对定位布局
- Android事件分发机制源码分析下----ViewGroup事件分发分析