为啥只有60分,求助大佬!
查看原帖
为啥只有60分,求助大佬!
979537
caizehao楼主2023/6/3 18:52

代码如下:

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

stack<char> s;
string str;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> str;
	int len=str.size();
	for(int i=0;i<len;i++){
		if(str[i]=='('){
			s.push(str[i]);
		}else{
			if(str[i]==')'){
				if(s.top()=='('){
					s.pop();
				}
			}
		}
	}
	if(!s.empty()){
		cout << "NO";
	}else{
		cout << "YES";
	}
	return 0;
}
2023/6/3 18:52
加载中...