首页 > 其他 > 详细

括号匹配&&计算问题

时间:2020-06-25 10:27:06      阅读:57      评论:0      收藏:0      [点我收藏+]

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;
}

 

括号匹配&&计算问题

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!