ECNU-2574 Principles of Compiler
题意:
给出编译规则,求是否满足条件
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的更多相关文章
- ECNUOJ 2574 Principles of Compiler
Principles of Compiler Time Limit:1000MS Memory Limit:65536KBTotal Submit:473 Accepted:106 Descripti ...
- (转)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-> ...
随机推荐
- oracle是数据库的学习第一节:数据库的安装
一.本地oracle服务器 1.安装oracle服务器,可以到oracle官方网站上下载与自己电脑匹配的服务器,一般用10g,或者11g; 2.打开cmd,打开sql*plus,之后可以写SQL语句了 ...
- 第十一篇、RxSwift
三. 什么是函数式编程? 什么是函数式编程呢? 函数式编程其实是一种编程思想, 代码写出来只是它的表现形式. 在面向对象的编程思想中, 我们将要解决的一个个问题, 抽象成一个个类, 通过给类定义属性和 ...
- Sublime Text 3下 Emmet 使用小技巧
Emmet常用技巧:(输入下面简写,按Tab键可触发效果) 生成 HTML 文档初始结构 html:5 或者 ! 生成 HTML5 结构 ...
- OC5_类别
// // NSString+Reverse.h // OC5_类别 // // Created by zhangxueming on 15/6/16. // Copyright (c) 2015年 ...
- java web中cookie的永久创建与撤销
一.首先是创建cookie 当在数据库中查找知道所输入的用户名和密码正确之后,就开始创建: String cb=request.getParameter("cb");//cb就是登 ...
- Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)
Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢) 1. 获取选中项: 获取选中项的Value值: $('select#sel option:selected').val() ...
- jQueryr .on方法解析
.On() 其实.bind(), .live(), .delegate()都是通过.on()来实现的,.unbind(), .die(), .undelegate(),也是一样的都是通过.off()来 ...
- NodeJS + Socket.io搭建聊天服务器
第一步:安装node git clone https://github.com/joyent/node.git cd node git checkout v0.10.33-release ./conf ...
- window.print打印指定div实例代码
window.print可以打印网页,但有时候我们只希望打印特定控件或内容,怎么办呢,请看下面的例子 首先我们可以把要打印的内容放在div中,然后用下面的代码进行打印. 复制代码代码如下: <h ...
- (转)《深入理解java虚拟机》学习笔记3——垃圾回收算法
Java虚拟机的内存区域中,程序计数器.虚拟机栈和本地方法栈三个区域是线程私有的,随线程生而生,随线程灭而灭:栈中的栈帧随着方法的进入和退出而进行入栈和出栈操作,每个栈帧中分配多少内存基本上是在类结构 ...