题意:

给出编译规则,求是否满足条件

A:= '(' B')'|'x'.
    B:=AC.
    C:={'+'A}.

其中{}表示里面的内容可以出现0次或者多次

注意点见代码注释

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int maxn = ; int pos;
int len;
char a[ maxn ]; bool solveA();
bool solveB();
bool solveC(); bool solveA(){
//printf("A:%c\n",a[pos]);
//if( pos>=len ) return false;
if( a[pos]=='(' ){
pos++;
if( solveB() ){
if( a[pos]==')' ){
pos++;/*该字符后面可能还有字符*/
return true;
}
else{
return false;
}
}
else
return false;
}
else
if( a[pos]=='x' ){
pos++;
return true;
}
else{
pos++;/*同理,该字符后面可能还有字符*/
return false;
}
} bool solveB(){
//printf("B:%c\n",a[pos]);
if( solveA() ){
return solveC();
}
else return false;
} bool solveC(){
if( pos>=len ) return false;
while( pos<len && a[pos]=='+' ){
pos++;
solveA();
}
return true;
} int main(){
int T;
scanf("%d",&T);
while( T-- ){
memset( a,'\0',sizeof( a ) );
scanf("%s",a);
pos = ;
len = strlen( a );
bool f = solveA();
if( pos<len ) {printf("Bad\n");continue;}
/*防止出现前半部分符合条件,后半部分不合的用例*/
if( f ) printf("Good\n");
else printf("Bad\n");
}
return ;
}

ECNU-2574 Principles of Compiler的更多相关文章

  1. ECNUOJ 2574 Principles of Compiler

    Principles of Compiler Time Limit:1000MS Memory Limit:65536KBTotal Submit:473 Accepted:106 Descripti ...

  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. iOS开发——model类模板(过滤null和ID)

            说明:model类模板已默认过滤null值,附加特殊情况的关键字ID名的冲突(需手动去掉注释代码).MyMessageModel为示例的名字.可以自己随便起. 1.自己创建一个继承与N ...

  2. 0<=i<iLen 在C++中

    for( i=0;0<= i<2; i++)这样的话会出现什么错误呢? 一直循环下去, 因为i>=一直成立

  3. 模板:多Case输入处理

    利用cin实现 while(cin >> value) { } 调试时使用Ctrl + Z 输入文件结束符

  4. 基于FPGA的按键扫描程序

    最近在学习FPGA,就试着写了个按键扫描的程序.虽说有过基于单片机的按键扫描处理经验,对于按键的处理还是有一些概念.但是单片机程序的编写通常都采用C写,也有用汇编,而FPGA却是采用VHDL或者Ver ...

  5. struts2 的action 向页面传值

    写一个Action类: public class LoginAction{ public String execute(){ return SUCCESS; } public void setValu ...

  6. CSS3单位

    em 做前端的应该对em不陌生,不是什么罕见的单位,是相对单位,参考物是父元素的font-size,具有继承的特点.如果字体大小是16px(浏览器的默认值),那么 1em = 16px. 不过,这样使 ...

  7. 窗体位置设置StartPosition属性

    有如下选项,分别含义如下: CenterParent                    窗体在其父窗体中居中.      CenterScreen                    窗体在当前 ...

  8. [OpenXml] Generate excel in memory and dump to file

    public static void GenerateExcelFromStream() { using (MemoryStream memoryStream = new MemoryStream() ...

  9. 如何保证写出来的程序没BUG

  10. 【Delphi】窗体阴影

    procedure TForm1.FormCreate(Sender: TObject); begin SetClassLong(Handle, GCL_STYLE, GetClassLong(Han ...