洛谷_P1739 表达式括号匹配_stack

//
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    int x,y,i;

    // while(  )            // 就离谱 用循环一直wa debug老久
    getline( cin,s,'@' );
    {
        x=y=0;
        for( i=0;i<s.size();i++ )
        {
            if( s[i]=='(' )         x++;
            else if( s[i]==')' )    y++;

            if( x<y )               break;
        }
        if( x==y )      cout<<"YES"<<endl;
        else            cout<<"NO"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/123931717