文章

60

粉丝

361

获赞

41

访问

497.9k

头像
签到题
P1501 西北工业大学2015机试题
发布于2021年1月17日 21:34
阅读数 7.1k

#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	while(cin>>s)
	{
		stack<char>st;
		for(int i=0;i<s.size();i++)
		{
			if(!st.empty())
			{
				if(st.top()=='('&&s[i]==')'||st.top()=='['&&s[i]==']')
					st.pop();
				else
					st.push(s[i]);
			}
			else
				st.push(s[i]);
		}
		if(!st.empty()) 
			cout<<"NO"<<endl;
		else
			cout<<"YES"<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发