ECNUOJ 2574 Principles of Compiler
Principles of Compiler
Time Limit:1000MS Memory Limit:65536KB
Total Submit:473 Accepted:106
Description
After learnt the Principles of Compiler,partychen thought that he can solve a simple expression problem.So he give you strings of less than 100 characters which strictly adhere to the following grammar (given in EBNF):
A:= '(' B')'|'x'.
B:=AC.
C:={'+'A}.
Can you solve them too?
Input
The first line of input gives the number of cases, N(1 ≤ N ≤ 100). N test cases follow.
The next N lines will each contain a string as described above.
Output
For each test case,if the expression is adapt to the EBNF above output “Good”,else output “Bad”.
Sample Input
3
(x)
(x+(x+x))
()(x)
Sample Output
Good
Good
Bad
Source
解题:几十万只草泥马呼啸而过,一直没搞懂{+A}的含义
重复 { ... } 也就是说这个是表示+A可以出现0次或多次
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
char str[maxn];
int cur;
bool A();
bool B();
bool C();
bool A() {
if(str[cur] == 'x') {
cur++;
return true;
}
if(str[cur] == '(') {
cur++;
if(B() && str[cur] == ')') {
cur++;
return true;
}
}
return false;
}
bool B() {
return A() && C();
}
bool C() {
while(str[cur] == '+'){
cur++;
if(!A()) return false;
}
return true;
}
int main() {
int kase;
scanf("%d",&kase);
getchar();
while(kase--) {
gets(str);
cur = ;
puts(A() && str[cur] == '\0'?"Good":"Bad");
}
return ;
}
ECNUOJ 2574 Principles of Compiler的更多相关文章
- ECNU-2574 Principles of Compiler
题意: 给出编译规则,求是否满足条件 A:= '(' B')'|'x'. B:=AC. C:={'+'A}. 其中{}表示里面的内容可以出现0次或者多次 注意点见代码注释 #include ...
- (转)Awesome Courses
Awesome Courses Introduction There is a lot of hidden treasure lying within university pages scatte ...
- Scala零基础教学【81-89】
第81讲:Scala中List的构造是的类型约束逆变.协变.下界详解 首先复习四个概念——协变.逆变.上界.下界 对于一个带类型参数的类型,比如 List[T]: 如果对A及其子类型B,满足 List ...
- 2.2 节的练习--Compiler principles, technologys, &tools
2.2 节的练习 2.2.1 考虑下面的上下文无关文法: S -> S S + | S S * | a 试说明如何使用该文法生成串 aa+a* 试为这个串构造一颗语法分析树 ⧗ 该文法生成的语言 ...
- Compiler Principles 语法分析
语法分析的两种思维方式:1:自顶向下分析 :从语法树的根部推下来一直推到需要确认的终结符号串为止:就是为了找到一个符号串的最左推导 自顶向下分析,因为文法有些是以非终结符开头的另外文法中还可能含有右部 ...
- Notes of Principles of Parallel Programming - TODO
0.1 TopicNotes of Lin C., Snyder L.. Principles of Parallel Programming. Beijing: China Machine Pres ...
- compiler
http://www.lingcc.com/2012/05/16/12048/ a list of compiler books — 汗牛充栋的编译器参考资料 Posted on 2012年5月16日 ...
- Java compiler level does not match解决方法
从别的地方导入一个项目的时候,经常会遇到eclipse/Myeclipse报Description Resource Path Location Type Java compiler level d ...
- idea报错:error java compilation failed internal java compiler error
idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...
随机推荐
- pthread 的 api 分类
pthreads defines a set of C programming language types, functions and constants. It is implemented w ...
- Acme Corporation UVA - 11613 费用流
Code: #include<cstdio> #include<cstring> #include<vector> #include<queue> #i ...
- (noip模拟十七)【BZOJ3930】[CQOI2015]选数-容斥水法
Description 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案.小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都求一次最大公 ...
- man 7 glob
GLOB(7) Linux Programmer's Manual GLOB(7) NAME glob - 形成路径名称 描述 (DESCRIPTION) 很久以前 在 UNIX V6 版 中 有一个 ...
- BZOJ 2683 简单题 cdq分治+树状数组
题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...
- Cocos2dx 小技巧(十五)话说ScrollView的delegate实现过程
附:本文參加了CSDN博客大赛.亲假设认为这篇文章不错,就大胆的来投上一票吧! !!http://vote.blog.csdn.net/Article/Details? articleid=34140 ...
- Linux线程相互排斥量--进程共享属性
多线程中.在相互排斥量和 读写锁的 属性中.都有一个叫 进程共享属性 . 对于相互排斥量,查询和设置这个属性的方法为: pthread_mutexattr_getpshared pthread_mut ...
- vs2012碰到生成时报该错误:项目中不存在目标 “XXXXXX”
vs2012碰到生成时报该错误:项目中不存在目标 "XXXXXX" 首先打开project文件,找到 以下信息: <Import Project="$(MSBuil ...
- poj_2481,Cows,树状数组
将e按从大到小排序,统计前i-1个中比 #include<iostream> #include<cstdio> #include<cstring> #include ...
- ES聚合底层机制-bucket深的话采用广度优先更好,而如果是年度统计还是深度优先好
见原文,仅仅摘录部分:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_preventing_combinatorial_exp ...