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