C language implementation of parentheses pairing problem

Source: Internet
Author: User

The code is as follows:

#include <stdio.h>#include<string.h>#include<stdlib.h>//Write a function that determines whether the parentheses matchintMatchcheck (CharA[],intLen) {    intFlag =0; Chars[10000]; intTop,i; Chartemp; //Initialize a stacktop =0;  for(i=0; i<len;i++){        if(a[i]=='['){//If the left parenthesis is directly into the stacks[++top]=A[i]; Continue; }        if(a[i]==']'){//if it is a closing parenthesis, try to matchtemp =S[top]; if(temp=='[') {flag=1; Top--; Continue; }Else{flag=0;  Break; }        }        if(a[i]=='('){//If the left parenthesis is directly into the stacks[++top]=A[i]; Continue; }        if(a[i]==')'){//if it is a closing parenthesis, try to matchtemp =S[top]; if(temp=='(') {flag=1; Top--; Continue; }Else{flag=0;  Break; }        }    }    if(flag&& (top==0)){        return 1; }Else{        return 0; }}intMain () {//prompt to enter a number    intN,i; scanf ("%d",&N); intLen; //judgment on N-Group data loops     intCount =1; intresult[5];  while(count<=N) {         Chara[10000]={' /'}; //read a line stringscanf"%s",&a); //to find the length of a stringLen =strlen (a); Result[count]=Matchcheck (A,len); Count++; }      for(i=1; i<count;i++){         if(Result[i]) {printf ("yes\n"); }Else{printf ("no\n"); }     }     return 0;}

Sample inputs and outputs are as follows:

C language implementation of parentheses 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.