谁能看一下这道题
  • 板块灌水区
  • 楼主ycx20120224
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/3/15 13:02
  • 上次更新2024/3/15 16:59:59
查看原帖
谁能看一下这道题
1057768
ycx20120224楼主2024/3/15 13:02

我的代码:

#include<iostream>
using namespace std;
string s;
int main(void)
{
	cin>>s;
	if(s[0]==')')
	{
		cout<<"no";
		return 0;
	}
	if(s[s.size()-1]=='(')
	{
		cout<<"no";
		return 0;
	}
	if(s.size()%2!=0)
	{
		cout<<"no";
		return 0;
	}
	int cnt=0;
	for(int i=0;i<=s.size();i++)
	{
		if(s[i]=='(' )
		{
			cnt++;
		}
		else if(cnt!=0)
		{
			cnt--;
		}
		if(cnt<0)
		{
			cout<<"no";
			return 0;
		}
	}
	if(cnt==0)
	{
		cout<<"yes";
	}
	else cout<<"nd";
	return 0;
 } 

错误数据输入:()(()

2024/3/15 13:02
加载中...