文章

94

粉丝

0

获赞

19

访问

2.8k

头像
括号匹配 题解:
P1501 西北工业大学机试题
发布于2026年1月25日 14:56
阅读数 33

栈匹配

#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
int main()
{
    char s[100];
    scanf("%s",s);
    int l=strlen(s);
//    printf("%s\n",s);
    stack<char> hash;
    if(s[0]=='['||s[0]=='(')
    {
        hash.push(s[0]);
    }
    else{
        printf("NO\n");
        return 0;
    } 
//    printf("%c",hash.top()); 
    for(int i=1;i<l;i++){
        if(s[i]=='[' or s[i]=='(')
        {
            hash.push(s[i]);
       &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发