50分求助!(超时)
查看原帖
50分求助!(超时)
996300
CMY2013楼主2024/3/26 21:58
#include<bits/stdc++.h>
using namespace std;
string s;
int n,ans=0;
stack<char> c;

int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		while(!c.empty())
		{
			c.pop();
		}
		c.push(s[i]);
		for(int j=i+1;j<n;j++)
		{
			if(!c.empty() && s[j]==c.top())
			{
				c.pop();
				if(c.empty())
				{
					ans++;
				}
			}
			else c.push(s[j]);
		}
	}
	cout<<ans;
	return 0;
}
2024/3/26 21:58
加载中...