3,6,7,9点RE,大佬帮忙看看为什么
查看原帖
3,6,7,9点RE,大佬帮忙看看为什么
792928
eastonwu楼主2024/3/7 13:35
#include<bits/stdc++.h>
using namespace std;
char a[256];
int n;
stack<char>s;
int main()
{
    scanf("%s",a);
    n=strlen(a);
    for(int i=0;i<n;i++)
    {
    	if(a[i]=='(')
    	{
    		s.push(a[i]);
		}
		else if(a[i]==')')
		{
			if(s.top()=='(')
			{	
			    s.pop();
		    }
		    else
			{
				printf("NO");
				return 0;
			}
		}
    	
	}
	if(!s.empty())
	{
		printf("NO");
		return 0;
	}
	else
	{
		printf("YES");
		return 0;
	}
}

谢谢大佬们!

2024/3/7 13:35
加载中...