STL version Brackets Match (not feel as fast as you used to emulate the array)

Source: Internet
Author: User

Data structure Experiment stack four: brace matching Time limit:1000ms Memory limit:65536k The title describes to you a string of characters, not exceeding 50 characters, which may include parentheses, numbers, letters, punctuation marks, spaces, and your task is to check () in this string of characters, [],{} matches.

Input input data has multiple groups, processing to the end of the file.

Output "yes" if matched, mismatch output "no"

Sample input
Sin (20+10) {[}]
Sample output
Yesno

Note: The strings you read may contain spaces.
#include <iostream> #include <string> #include <stdio.h> #include <string.h> #include <map > #include <stack> #include <deque>//double-ended queue # include <queue> #include <algorithm> #include <    Ctype.h>using namespace Std;int Main () {char s[100];    int I, J;        while (gets (s)!=null) {unsigned int len=strlen (s);        stack<char>q; for (i=0; i<len; i++) {if (s[i]== ' | | | s[i]== ' [' | | |            s[i]== ' {') {Q.push (s[i]);                    } else if (s[i]== ') ') {if (Q.empty () | | q.top ()! = ' (') {                Q.push (S[i]);                } else if (q.top () = = ' (') {q.pop ();                    }} else if (s[i]== '] ') {if (Q.empty () | | | q.top () = ' [') {                Q.push (S[i]);     } else if (q.top () = = ' [')           {Q.pop ();                    }} else if (s[i]== '} ') {if (Q.empty () | | | q.top ()! = ' {') {                Q.push (S[i]);                } else if (q.top () = = ' {') {q.pop ();        }}} if (Q.empty ()) printf ("yes\n");    else printf ("no\n"); } return 0;}

STL version Brackets Match (not feel as fast as you used to emulate the array)

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.