Nyoj 2 Bracket pairing problem

Source: Internet
Author: User

Bracket pairing problem time limit:MS | Memory limit:65535 KB Difficulty:3
Describe
now, with a sequence of parentheses, you should check that the line brackets are paired.
Input
the first line enters a number n (0<n<=100), which indicates that there are n sets of test data. The next n lines enter multiple sets of input data, each set of input data is a string s (S is less than 10000, and S is not an empty string), and the number of test data groups is less than 5 groups. Data guarantee S contains only "[", "]", "(", ")" Four characters
Output
The
output of each set of input data is one row, if the parentheses contained in the string are paired, the output is yes, and if you do not pair the output no
Sample input
3[(]) (]) ([[[] ()])
Sample output
Nonoyes

Classic Stack problem:
1  2#include <iostream>3 using namespacestd;4#include <stack>5#include <string>6 intMain ()7 {8     intN//n Group of data9Cin>>N;Tenstack<Char> SS;strings; One      while(n--) A     { -Cin>>s; -         intlen=s.size (); the          while(!ss.empty ()) - Ss.pop (); -Ss.push ('#'); -          for(intI=0; i<len;i++) +         { -             if(s[i]=='['|| s[i]=='(') + Ss.push (S[i]); A             Else at                 { -                     if(s[i]==']') -                         if(Ss.top () = ='[') - Ss.pop (); -                         Else - Ss.push (S[i]); in                     if(s[i]==')') -                         if(Ss.top () = ='(') to Ss.pop (); +                         Else - Ss.push (S[i]); the             } *                      $         }Panax Notoginseng         if(Ss.top () = ='#') -cout<<"yes\n"; the         Else +cout<<"no\n"; A     } the     return 0; + } -         

Nyoj 2 Bracket pairing problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.