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-> ...
随机推荐
- 8个应该去逛逛JQuery的学习网站
根据国外科技网站 W3Techs 一项调查了近100万个网站数据显示,jQuery是目前最流行的 JavaScript 库.对于初学者来说,有的时候很难找到一个好的学习jQuery的网站,所以本文收集 ...
- 比较X与Y的大小,绝对精准!!!!!!
代码! #include<stdio.h> int max(int a,int b) { int x; x=a+b; return x; } int main() { int i,n,t; ...
- Qt自定义菜单项
经常会看到一些菜单的部分项是由几个按钮组成的,如酷狗.QQ.360都有类似菜单,对于常规的菜单项,图标 + 文字 实现一个事件,很容易完成,那么怎么自定义菜单项呢? Qt提供了支持,就是利用QWidg ...
- Java多线程(四) 线程池
一个优秀的软件不会随意的创建.销毁线程,因为创建和销毁线程需要耗费大量的CPU时间以及需要和内存做出大量的交互.因此JDK5提出了使用线程池,让程序员把更多的精力放在业务逻辑上面,弱化对线程的开闭管理 ...
- OpenCV3读取视频或摄像头
我们可以利用OpenCV读取视频文件或者摄像头的数据,将其保存为图像,以用于后期处理.下面的实例代码展示了简单的读取和显示操作: // This is a demo introduces you to ...
- jQuery自己编写插件()
引言: 在项目中不同页面经常要用到已经写好的交互,比如弹窗,比如下拉菜单,比如选项卡,比如删除... 此时如果每次都把代码copy一份无疑是一件比较麻烦并且无趣的事情,而且个人认为有些low了,我们可 ...
- NSS_03 过滤器
asp.net mvc3有四类过滤器:授权, 操作,结果, 异常.操行的顺序为:授权,操作,结果,异常. 首先看一下TempData: 数据只能经过至多一次的Controller传递, 并且每个元素至 ...
- JAVASCRIPT实现翻页保存已勾选的项目
<input type="checkbox" name="a" value="1" /><br/> <inpu ...
- Cassandra1.2文档学习(17)—— CQL数据模型(上)
参考文档:http://www.datastax.com/documentation/cql/3.0/webhelp/index.html#cql/ddl/ddl_anatomy_table_c.ht ...
- 前端encodeURIComponent 和后端http_build_query配合
解决特殊字符不能转义 1. function fixedEncodeURIComponent (str) { return encodeURIComponent(str).replace(/[!' ...