Respuesta :
Answer:
See attachment below
Program to check for matching symbols
// Program is written in C++
// Comments are used for explanatory purposes
// Program Starts here
#include<bits/stdc++.h>
using namespace std;
bool CheckParenthesis(string word)
{
int pos = 0;
char singlechar;
stack<char> stackchar;
for (pos=0; pos<word.length(); pos++)
{
//Check for opening paranthesis
if (word[pos]=='('||word[pos]=='['||word[pos]=='{')
{
stackchar.push(word[pos]);
continue;
}
if (stackchar.empty())
return false;
switch (word[pos])
{
//Check for closing paranthesis
case ')':
singlechar = stackchar.top();
stackchar.pop();
if (singlechar=='{' || singlechar=='[') {
return false; }
break;
case ']':
singlechar = stackchar.top();
stackchar.pop();
if (singlechar =='(' || singlechar == '{') {
return false; }
break;
}
case '}':
singlechar = stackchar.top();
stackchar.pop();
if (singlechar=='(' || singlechar=='[') {
return false; }
break;
}
return (stackchar.empty());
}
// Main Program Starts Here
int main()
{
//Declare String
string word;
cout<<"Enter some string texts:";
cin>>word;
//Check for matching symbols
if (CheckParenthesis(word))
cout << "Matching Symbols";
else
cout << "No Matching Symbols";
return 0;
}

