UVA 673 Bracket Matching problem

Source: Internet
Author: User

Note: Empty line to output yes, to use get Read function, this problem let me learn to get and scanf function in addition to the space problem or

have a the difference between, scanf put the space, Tab, enter all as the end flag, will not be read into them, the back automatically add ' \ ', so space, enter, Tab

are in buffer, which can be read with GetChar (), but the Get () function will also treat the carriage return as the end flag, but they will read the

into, read The string is ' GetChar ', so they will not exist in the buffer, that is, they can not be read with the ...

Release code:

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <stack>using namespace std; Char A[130];int main () {stack <char> s;int n,flag,i;char ch;scanf ("%d", &n); GetChar (); while (n--) {flag=1;gets (a);//SCANF ("%s", a), if (a[0]== ') {puts ("yes"); continue;} Flag=0;int len = strlen (a); for (i=0; i<len; i++) {if (a[i]== ' (' | | a[i]== ' [') {S.push (a[i]);} Else{if (S.empty ()) {puts ("No"); flag=1;break;} Else{ch = S.top (); S.pop (); if (a[i]== ') ') {if (ch!= ' (') {puts ("No"); flag=1;break;}} Else{if (ch!= ' [') {puts ("No"); flag=1;break;}}}} if (!flag) {   if (S.empty ()) puts ("Yes");   Elseputs ("No");    }    while (!s.empty ())    {    s.pop ();    }    


UVA 673 Bracket Matching 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.