ECNU-2574 Principles of Compiler

题意:

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

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

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

注意点见代码注释

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 const int maxn = 205;
 5
 6 int pos;
 7 int len;
 8 char a[ maxn ];
 9
10 bool solveA();
11 bool solveB();
12 bool solveC();
13
14 bool solveA(){
15     //printf("A:%c\n",a[pos]);
16     //if( pos>=len ) return false;
17     if( a[pos]==‘(‘ ){
18         pos++;
19         if( solveB() ){
20             if( a[pos]==‘)‘ ){
21                 pos++;/*该字符后面可能还有字符*/
22                 return true;
23             }
24             else{
25                 return false;
26             }
27         }
28         else
29             return false;
30     }
31     else
32         if( a[pos]==‘x‘ ){
33             pos++;
34             return true;
35         }
36     else{
37         pos++;/*同理,该字符后面可能还有字符*/
38         return false;
39     }
40 }
41
42 bool solveB(){
43     //printf("B:%c\n",a[pos]);
44     if( solveA() ){
45         return solveC();
46     }
47     else return false;
48 }
49
50
51 bool solveC(){
52     if( pos>=len ) return false;
53     while( pos<len && a[pos]==‘+‘ ){
54         pos++;
55         solveA();
56     }
57     return true;
58 }
59
60
61 int main(){
62     int T;
63     scanf("%d",&T);
64     while( T-- ){
65         memset( a,‘\0‘,sizeof( a ) );
66         scanf("%s",a);
67         pos = 0;
68         len = strlen( a );
69         bool f = solveA();
70         if( pos<len ) {printf("Bad\n");continue;}
71         /*防止出现前半部分符合条件,后半部分不合的用例*/
72         if( f ) printf("Good\n");
73         else printf("Bad\n");
74     }
75     return 0;
76 }

时间: 2025-01-02 13:49:03

ECNU-2574 Principles of Compiler的相关文章

ECNUOJ 2574 Principles of Compiler

Principles of Compiler Time Limit:1000MS Memory Limit:65536KBTotal 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 ch

Scala 深入浅出实战经典 第87讲:Scala中使用For表达式做查询

for(生成器;定义;过滤器) 来做数据过滤查询 package com.dt.scala.forexpression case class Book(title : String , authors : List[String]) object For_Query { def main(args: Array[String]) { val books: List[Book] = List( Book("Structure and Interpretation ", List(&quo

(转)Awesome Courses

Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scattered across the internet. This list is an attempt to bring to light those awesome courses which make their high-quality material i.e. assignments, lect

compiler

http://www.lingcc.com/2012/05/16/12048/ a list of compiler books — 汗牛充栋的编译器参考资料 Posted on 2012年5月16日 by Lingcc | 14 Replies 前不久,有位<编译点滴>网友询问编译器方向的参考资料.其实之前讨论过一些编译器相关的在线资料–<有写编译器的冲动?这些资料很重要>.这篇博文就来总结总结编译技术相关的各类图书资料,供各位参考.这个书列是结合本人所了解的内容整理出来的,限于

Design Principles from Design Patterns

Leading-Edge Java A Conversation with Erich Gamma, Part III by Bill Venners June 6, 2005 Erich Gamma lept onto the software world stage in 1995 as co-author of the best-selling book Design Patterns: Elements of Reusable Object-Oriented Software (Addi

maven -- 问题解决(三)Java compiler level does not match the version of the installed Java project facet

问题: Java compiler level does not match the version of the installed Java project facet 解决方法如下: properties->Java Compiler,修改JDK版本,然后Apply

Coursera compiler Set up environment and Run first program

Environment, Ubuntu 14.04 set up guide Set up cool compiler 1. sudo apt-get install flex bison build-essential csh openjdk-6-jdk libxaw7-dev libc6-i386 2. Make the /usr/class directory sudo mkdir /usr/class 3. Make the directory owned by you sudo cho

Error:java: Compilation failed: internal java compiler error

1.新建maven项目时,jdk用的是1.8,但是编译代码提示失败 IDE要设置几个地方 1.点击项目 选择 project structure 2.设置project的 project sdk 和 project language level 3.设置modules的jdk版本,选择8 4.选择setting,设置java compiler 选择jdk1.8

Type Java compiler level does not match the version of the installed Java project facet.项目内容没错但是项目上报错,不影响运行

1.Window->Show View->Problems 2.在项目上右键properties->project Facets->修改右侧的version  保持一致 3.window->preferences->Java->Compiler->设置右侧的Compiler compliance level 4.window->preferences->java->Installed JREs->设置或者选择右侧的Installed