uva 384 Slurpys

题目:给了slury的语法(由slimp和slump组成),语法分析判断

注意:函数变量用形参

函数设置一个begin变量真的很方便

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
bool slump(char m[61],int &begin){
    if(m[begin]=='D' || m[begin]=='E'){
        if (m[++begin] == 'F') {
            while (m[++begin]=='F');
            if(m[begin]=='G') return true;
            else if(m[begin]=='D' || m[begin]=='E') return slump(m, begin);
            else return false;
        }
        else return false;
    }
    else return false;
}
//DFG
//  01234567
//DFG, EFG, DFFFFFG, DFDFDFDFG, DFEFFFFFG
//DFEFF, EFAHG, DEFG, DG, EFFFFDG

bool slimp(char m[61],int &begin){
    if (m[begin] == 'A') {
        begin++;
        if (m[begin] == 'H') return true;
        else if (m[begin] == 'B'){
            if(slimp(m, ++begin)){
                if (m[++begin] == 'C') return true;
                else return false;
            }
            else return false;
        }
        else if (m[begin]=='D' || m[begin]=='E'){
            if(slump(m, begin)){
                if (m[++begin] == 'C') return true;
                else return false;
            }
            else return false;
        }
        else return false;
        
    }
    else return false;
}
//AH, ABAHC, ABABAHCC, ADFGC, ADFFFFGC, ABAEFGCC, ADFDFGC
int main(){
    int num;
    cin>>num;
    char input[61];
    cout<<"SLURPYS OUTPUT"<> input;
        int b = 0;
       // cout<



你可能感兴趣的:(uva)