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的更多相关文章

  1. ECNU-2574 Principles of Compiler

    题意: 给出编译规则,求是否满足条件 A:= '(' B')'|'x'.    B:=AC.    C:={'+'A}. 其中{}表示里面的内容可以出现0次或者多次 注意点见代码注释 #include ...

  2. (转)Awesome Courses

    Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scatte ...

  3. Scala零基础教学【81-89】

    第81讲:Scala中List的构造是的类型约束逆变.协变.下界详解 首先复习四个概念——协变.逆变.上界.下界 对于一个带类型参数的类型,比如 List[T]: 如果对A及其子类型B,满足 List ...

  4. 2.2 节的练习--Compiler principles, technologys, &tools

    2.2 节的练习 2.2.1 考虑下面的上下文无关文法: S -> S S + | S S * | a 试说明如何使用该文法生成串 aa+a* 试为这个串构造一颗语法分析树 ⧗ 该文法生成的语言 ...

  5. Compiler Principles 语法分析

    语法分析的两种思维方式:1:自顶向下分析 :从语法树的根部推下来一直推到需要确认的终结符号串为止:就是为了找到一个符号串的最左推导 自顶向下分析,因为文法有些是以非终结符开头的另外文法中还可能含有右部 ...

  6. Notes of Principles of Parallel Programming - TODO

    0.1 TopicNotes of Lin C., Snyder L.. Principles of Parallel Programming. Beijing: China Machine Pres ...

  7. compiler

    http://www.lingcc.com/2012/05/16/12048/ a list of compiler books — 汗牛充栋的编译器参考资料 Posted on 2012年5月16日 ...

  8. Java compiler level does not match解决方法

    从别的地方导入一个项目的时候,经常会遇到eclipse/Myeclipse报Description  Resource Path Location Type Java compiler level d ...

  9. idea报错:error java compilation failed internal java compiler error

    idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...

随机推荐

  1. 51nod1073-约瑟夫环,递归。

    N个人坐成一个圆环(编号为1 - N),从第1个人开始报数,数到K的人出列,后面的人重新从1开始报数.问最后剩下的人的编号. 例如:N = 3,K = 2.2号先出列,然后是1号,最后剩下的是3号. ...

  2. 由Request Method:OPTIONS初窥CORS(转)

    刚接触前端的时候,以为HTTP的Request Method只有GET与POST两种,后来才了解到,原来还有HEAD.PUT.DELETE.OPTIONS…… 目前的工作中,HEAD.PUT.DELE ...

  3. CF1005F Berland and the Shortest Paths (树上构造最短路树)

    题目大意:给你一个边权为$1$的无向图,构造出所有$1$为根的最短路树并输出 性质:单源最短路树上每个点到根的路径 ,一定是这个点到根的最短路之一 边权为$1$,$bfs$出单源最短路,然后构建最短路 ...

  4. Ubuntu 16.04 Chrome浏览器安装flash player插件

    1:官网下载插件  flash palyer lash_player_npapi_linux_debug.x86_64.tar.gz 2:解压 提取 libpepflashplayer.so 3:手动 ...

  5. thttpd 在S3C6410的移植-web服务程序的应用

    1.    在VMWare 虚拟机上将arm-linux-gcc 4.3.1配置好:2.    下载thttpd软件包并解压:3.    在thttpd根目录下运行:  ./configure:4.  ...

  6. pandas 7 合并 merge 水平合并,数据会变宽

    pd.merge( df1, df2, on=['key1', 'key2'], left_index=True, right_index=True, how=['left', 'right', 'o ...

  7. [HAOI2009]毛毛虫(树形dp)

    [HAOI2009]毛毛虫 题目描述 对于一棵树,我们可以将某条链和与该链相连的边抽出来,看上去就象成一个毛毛虫,点数越多,毛毛虫就越大.例如下图左边的树(图 1 )抽出一部分就变成了右边的一个毛毛虫 ...

  8. 10、匿名内部类、枚举类、日期、Math、Random、String、equals、StringBuffer、包装类、对象数组、克隆,标准输出3

    1对象的克隆(clone) 单纯的同类的两个对象a0 a00,a0=a00只是栈指向同一个堆,而不是开辟两个新堆,修改其中一个,另一个也会受牵连. 需要重写Clone()方法,并且实现Cloneabl ...

  9. 使用具体解释及源代码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter

    Adapter相当于一个数据源,能够给AdapterView提供数据.并依据数据创建相应的UI.能够通过调用AdapterView的setAdapter方法使得AdapterView将Adapter作 ...

  10. SVN过滤设置

    为了方便管理我们的系统版本号.非常多人会用到SVN,开发中我们经经常使用到SVN插件, 可是对于某些文件的缓存来说, 我们仅仅要有操作缓存便会保存一次, 每次提交非常是麻烦, 可能有的文件或者目录我们 ...