文章

2

粉丝

138

获赞

0

访问

10.6k

头像
有手就行做法
P1838 南京理工大学机试题
发布于2022年1月10日 10:57
阅读数 6.3k

#include
using namespace std;
#define ll  long long
#define _for(i,a,b) for(int i=(a);i<=(b);i++)


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);	
	
	string s;
	cin>>s;
	int len = s.length();	
	int ans = 0;
	 	
	char ch1[5] = {' ','<','(','{','['};
	char ch2[5] = {' ','>',')','}',']'};
	_for(i,0,len-1){
		_for(j,1,5){
			if(s[i]==ch1[j]) ans+=j;
			if(s[i]==ch2[j]) ans-=j;
		}
	}
	if(!ans)   cout<<"yes";
	else cout<<"no";
	return 0;
} 

不用花里胡哨的,直接加减,如果数据有有括号在前,ans<0直接输出并return即可

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发