HDOJ 1433 Simply Syntax
来源:互联网 发布:c 语言mark 编辑:程序博客网 时间:2024/04/29 17:19
Simply Syntax
Problem 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
1. Every character from p through z is a correct sentence. //每一个语法都由p到z贯穿,所以最后一个字母需为p到z
2. If s is a correct sentence, then so is Ns. //s语法正确,Ns语法也正确
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int fan(char a[]){int sum=0,i,len;len=strlen(a);for (i=len-1;i>=0;i--)//倒着判断{if (a[i]>='p'&&a[i]<='z')sum++;else if (a[i]=='N'){continue;}else if(a[i]=='C'||a[i]=='D'||a[i]=='E'||a[i]=='I')sum--;elsereturn 0;if (sum<1)return 0;}if (sum==1)return 1;elsereturn 0;}int main(){int i;char str[300];while (scanf ("%s",str)!=EOF){//gets(str);if (fan(str))printf ("YES\n");elseprintf ("NO\n"); } return 0;}
0 0
- HDOJ 1433 Simply Syntax
- Hdoj 1433 Simply Syntax 【string】
- hdoj Simply Syntax 1433 (模拟)
- hdoj 1433 Simply Syntax【模拟】
- hdoj.1433 Simply Syntax【递归调用】 2015/04/24
- Hdu 1433 Simply Syntax【dfs枚举】
- POJ1126 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 右线性文法的归约
- POJ-1126——Simply Syntax (暴力扫一遍)
- Simply JavaScript
- Simply memorize sth
- Simply Rails 2 [ILLUSTRATED]
- php,zip类的使用
- Android Studio导入一些官方示例的问题
- Leetcode_106_Construct Binary Tree from Inorder and Postorder Traversal
- 【Matlab】num2str实现数字1到字符串0001的变换
- linux下tar.gz、tar、bz2、zip等解压缩、压缩命令
- HDOJ 1433 Simply Syntax
- find命令详解(上)
- 后缀数组 da算法
- 集合遍历 Iterator Foreach
- Python开发简单爬虫学习笔记(2)
- HibernateSearch
- Attention Mechanism in Deep Learninig
- NYOJ 308-Substring【模拟】
- find命令详解(中)