文章

2

粉丝

138

获赞

0

访问

12.1k

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

  1. #include
  2. using namespace std;
  3. #define ll long long
  4. #define _for(i,a,b) for(int i=(a);i<=(b);i++)
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. cout.tie(0);
  9. string s;
  10. cin>>s;
  11. int len = s.length();
  12. int ans = 0;
  13. char ch1[5] = {' ','<','(','{','['};
  14. char ch2[5] = {' ','>',')','}',']'};
  15. _for(i,0,len-1){
  16. _for(j,1,5){
  17. if(s[i]==ch1[j]) ans+=j;
  18. if(s[i]==ch2[j]) ans-=j;
  19. }
  20. }
  21. if(!ans) cout<<"yes";
  22. else cout<<"no";
  23. return 0;
  24. }

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

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发