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-> ...
随机推荐
- 基于localStorage的登录注册
以下代码,如果有地方有错,请直接指出,我会改进的(只改错误,不改逻辑,因为我自己是不会这样写代码的,这个只适合初学者): <!DOCTYPE html> <html> < ...
- STM8S103-STVD建立汇编代码项目
转载:http://blog.csdn.net/u010093140/article/details/49983397 STVD本来就比较少人用,STVD汇编就更少人用了,不过STM8汇编我自己还是满 ...
- mongodb报错:connection refused because too many open connections: 819
问题: 发现mongodb无法连接,查看mongodb日志,出现大量的如下报错: [initandlisten] connection refused because too many open co ...
- Vim常用命令及配置方案
Vim常用命令及配置方案 几句话 很久之前就接触到vim,初学那阵觉得vim很酷炫,但确实对新手不是很友好.我也就简单看了下基本操作就上手了,但又不是长期在vim下工作,这就导致了每一次重新使用v ...
- [细节版]Let'sEncrypt 免费通配符/泛域名SSL证书添加使用教程
参考网址:https://lnmp.org/faq/letsencrypt-wildcard-ssl.html 使用的dns服务商:阿里云 , 更多服务商地址可见参考网址. 遇见的问题一. [Sat ...
- JAVA关于byte数组与String转换的问题
1 public class ToString{ public static void main(String[] args){ String aa = "hellow"; byt ...
- 洛谷 P3662 [USACO17FEB]Why Did the Cow Cross the Road II S
P3662 [USACO17FEB]Why Did the Cow Cross the Road II S 题目描述 The long road through Farmer John's farm ...
- Qt之pro配置多个子工程/子模块
简述 进行Qt项目开发的时候,尤其是大型项目,经常涉及多工程/多模块问题,其主要思想还是模块化,目的是为了降低程序复杂度,使程序设计.调试和维护等操作简单化. 简述 配置 效果 多工程 多模块 更多参 ...
- C++ 数字、string 简便互转
一.数字转为 string 类型 借用 sprintf 函数: char buffer[256]; int counter = 10; sprintf(buffer,"%04i", ...
- angularjs 缓存 $q
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...