码迷,mamicode.com
首页 > 其他好文 > 详细

括号匹配&&计算问题

时间:2020-06-25 09:28:29      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:parent   pre   ima   com   amp   color   code   mic   计算   

1.括号匹配

技术图片

int isMatched(char left,char right){
    if(left == ‘(‘&& right == ‘)‘){
        return 1;
    }else if(left == ‘[‘&&right ==‘]‘){
        return 1;
    }else if(left == ‘{‘&&right ==‘}‘){
        return 1;
    }else{
        return 0;
    }
}
int isParenthesesBalanced(char exp[]){
    char s[MaxSize];int top=-1;
    for(int i=0;exp[i]!=‘\0‘;i++){
        if(exp[i] ==‘(‘ ||exp[i] ==‘{‘||exp[i]==‘[‘){
            s[++top]=exp[i];
        }
        if(exp[i] == ‘)‘||exp[i] == ‘}‘||exp[i]==‘]‘){
            if(top ==-1){
                return 0;
            }
            char left=s[top--];
            if(isMatched(left,exp[i]) == 0){
                return 0;
            }
        }
    }
    if(top>-1){
        return 0;
    }
    return 1;
}

 

2.计算问题

技术图片

 

 

int calF(int m){
    int cum=1;
    int s[MaxSize],top=-1;
    while(m!=0){
        s[++top]=m;
        m/=3;
    }
    while(top!=-1){
        cum*=s[top--];
    }
    return cum;
}

 

括号匹配&&计算问题

标签:parent   pre   ima   com   amp   color   code   mic   计算   

原文地址:https://www.cnblogs.com/jcahsy/p/13191061.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!