#include<stdio.h>
#include<stdlib.h>
#include<time.h>

typedef struct Node *NodePtr;
typedef struct Node{
	int pos;
	char symb;
	NodePtr next;
}Node;

NodePtr top;

int empty(){
	if(top==NULL){
		return 1;
	}else{
		return 0; 
	}
}

void push(char symb,int pos){
	NodePtr newNode = (Node*)malloc(sizeof(Node));
	newNode->pos=pos;
	newNode->symb=symb;
	newNode->next=top;
	
	top = newNode;
	
}

NodePtr pop(){
	if(empty()==1){
		return NULL;
	}else{
		NodePtr temp=top;
		top = top->next;
 		return temp;
	}	
} 

void prints(NodePtr top){
	NodePtr current=top;
	while(current!=NULL){
		printf("%d ",current->symb);
		current = current->next;
	}
	printf("\n");
}

int main(){
	int pos=0;
	char symb;
	while((symb=getchar())!='\n'){
		if(symb=='('||symb=='['){
			if(symb=='('){
				push(symb,pos);
			}else{
				push(symb,pos);
			}
		}else if(symb==')'||symb==']'){
			if(!empty()){
				NodePtr left_parenthesis_stack=pop();
				
				char left_parenthesis=left_parenthesis_stack->symb;
				int left_parenthesis_pos=left_parenthesis_stack->pos;
				char right_parenthesis=symb;
				int right_parenthesis_pos=pos;
				
				if(left_parenthesis=='('&&right_parenthesis==')'){
					printf("(%d,%d)",left_parenthesis_pos,right_parenthesis_pos);
					printf("\n");
				}else if(left_parenthesis=='['&&right_parenthesis==']'){
					printf("[%d,%d]",left_parenthesis_pos,right_parenthesis_pos);
					printf("\n");
				}else if(left_parenthesis=='('&&right_parenthesis==']'){
					printf("the right parenthesis ] in %d cannot find the left parenthesis [",right_parenthesis_pos);
					printf("\n");
				}else if(left_parenthesis=='['&&right_parenthesis==')'){
					printf("the right parenthesis ) in %d cannot find the left parenthesis (",right_parenthesis_pos);
					printf("\n");
				}	
			}
		}
		pos++;	 
	}
	while(top!=NULL){
		NodePtr left_parenthesis_stack=pop();
		char left_parenthesis_symb=left_parenthesis_stack->symb;
		int left_parenthesis_pos=left_parenthesis_stack->pos;
		if(left_parenthesis_symb=='('){
			printf("the left parenthesis ( in %d cannot find the right parenthesis )",left_parenthesis_pos);
			printf("\n");
		}else if(left_parenthesis_symb=='['){
			printf("the left parenthesis [ in %d cannot find the right parenthesis ]",left_parenthesis_pos);
			printf("\n");
		}
	} 
} 

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: