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. 51nod 2020 排序相减(暴力解法)

    题目: 代码: #include <bits\stdc++.h> using namespace std; int trim(int x){ ]; ;i < ; i++){ a[i] ...

  2. 关于jsp web项目,jsp页面与servlet数据不同步的解决办法(报错404、405等)即访问.jsp和访问web.xml中注册的/servlet/的区别

    报错信息: Type Status Report Message HTTP method GET is not supported by this URL Description The method ...

  3. hdu 6082 - 完全背包,打表。

    2017-08-06 15:02:50 Accepted 1003 187 MS 2168 K G++ redips 对背包有了进一步的认识 ----------------------------- ...

  4. Manacher笔记

    (其实还是回文自动机好用,毛子真是牛逼) Manacher #include<iostream> #include<cstring> #include<cstdio> ...

  5. CF939F Cutlet (单调队列优化DP)

    题目大意:要煎一块有两个面的肉,只能在一段k不相交的时间段$[l_{i},r_{i}]$内翻转,求$2*n$秒后,保证两个面煎的时间一样长时,需要最少的翻转次数,$n<=100000$,$k&l ...

  6. scrapy爬取boss直聘实习生数据

    这个..是我最近想找实习单位..结果发现boss上很多实习单位名字就叫‘实习生’.......太不讲究了 == 难怪一直搜不到..咳,其实是我自己水平有限,有些简历根本就投不出去 == 所以就想爬下b ...

  7. 洛谷 P1005 矩阵取数游戏 (区间dp+高精度)

    这道题大部分时间都在弄高精度-- 还是先讲讲dp吧 这道题是一个区间dp,不过我还是第一次遇到这种类型的区间dp f[i][j]表示取了数之后剩下i到j这个区间的最优值 注意这里是取了i之前和j之后的 ...

  8. Camera Calibration 相机标定:原理简介(一)

    1 相机标定常见方法 广义来说,相机标定不单包括成像过程的几何关系标定,还包括辐射关系的标定,本文只探讨几何关系.相机标定是3D计算机视觉(Computer Vision)里从2D图像中提取量测信息的 ...

  9. [MST] Remove Model Instances from the Tree

    In this lesson we will dive a bit more into the tree semantics of MST. In this lesson you will learn ...

  10. Android ListView动画实现方法

    在Android中listview是最经常使用的控件之中的一个,可是有时候我们会认为千篇一律的listview看起来过于单调,于是就产生了listView动画,listview载入了动画会让用户体验更 ...