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. kindEditor编写插件遇到的问题

    kindEditor是一个功能强大的在线文本编辑器,而且提供了插件扩展功能,更好的满足用户各方面的需求.在项目中,我们就有如此的需求:在kindEditor编辑器中,添加一条下划线,并且在下划线的中间 ...

  2. CTSC2012 熟悉的文章 广义后缀自动机_单调队列

    没啥难的,主要是单调队列忘了咋求了QAQ... Code: #include <cstdio> #include <algorithm> #include <cstrin ...

  3. javaweb实现教师和教室管理系统 java jsp sqlserver

    1,程序设计思想 (1)设计三个类,分别是工具类(用来写连接数据库的方法和异常类的方法).信息类(用来写存储信息的方法).实现类(用来写各种操作数据库的方法) (2)定义两个jsp文件,一个用来写入数 ...

  4. Django学习之配置篇

    MTV Model Template View 数据库 模版文件 业务处理 了解Django框架,功能齐全 一.安装Django&Django基本配置 安装Django pip3 django ...

  5. python 退出程序的执行

    使用sys.exit()退出当前程序的执行 import sys if x==0: sys.exit()

  6. 【BZOJ 1303】 [CQOI2009]中位数图

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是1..n的排列. 设b的位置为i. 设i右边的数字,比b大的为1,比b小的为-1. (i左边的位置数字也一样设置成1和-1 则 ...

  7. 50个经典Sql语句

    50个经典Sql语句 --1.学生表 Student(S,Sname,Sage,Ssex) --S 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表  Cours ...

  8. SQL 字符串操作函数

    SQL 字符串操作函数 学习了: https://www.cnblogs.com/wangzhe688/p/6046654.html 一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的A ...

  9. [MST] Loading Data from the Server using lifecycle hook

    Let's stop hardcoding our initial state and fetch it from the server instead. In this lesson you wil ...

  10. Unity 相机花式分屏

    花式分屏,顾名思义,可以实现各种不规则几何边界的分屏,是无法直接通过调整相机视口能达到效果的(只能实现矩形的分屏),例如斜对角分屏,几何图形分屏: 假设我们有两个相机,需要上面的斜对角分屏画面,和镜子 ...