栈·操作:
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
using namespace std;
int main()
{
stack<char>s;
string str;
cin >> str;
for (int i = 0; str[i] == '@'; i++)
{
if (str[i] == '(') s.push('(');
if (str[i] == ')')
{
if (s.empty())
{
cout << "NO" << endl;
return 0;
}
else s.pop();
}
}
s.empty() ? cout << "YES" << endl : cout << "NO\n";
return 0;
}
普通方法:
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
using namespace std;
int main()
{
string s;
cin >> s;
int left = 0,right = 0;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '(') left++;
if (s[i] == ')') right++;
if (s[i] == '@') break;
}
left == right ? cout << "YES\n" : cout << "NO\n";
return 0;
}