needs correction doesnt run
needs correction doesnt run
#include <iostream>
#include <stack>
using namespace std;
int matchingBracketsstringexprstringexprstringexpr
{
stack<char> s;
char x;
for inti=0;i<expr.length(inti=0;i<expr.length(inti=0;i<expr.length(; i++)
{
if expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain([Math Processing Error]expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain(
{
string expr;
int res;
getline(cin,exprcin,expr)cin,expr);
res=matchingBracketsexprexpr;
if res==0res==0
cout << "No mistake";
else
cout << res;
return 0;
}
![Problem Description:
Your friend keeps finding mistakes in his code due to unmatched brackets errors. You, as a good
friend, decided to help him by developing a program that will find errors in the usage of different
types of brackets. A Code can contain any of the following brackets []{}(), where the opening
brackets are [,{, and (and the closing brackets corresponding to them are ],}, and ).
Being a good friend, you want your program not to only detect that there is an error in the
usage of brackets, but also point to the exact place in the code with the problematic bracket.
Using C++/CPP
Requirements:
1. Write a program that finds the first unmatched closing bracket which either does not
have an opening bracket before it, or closes the wrong opening bracket, like } in ()[}. If
there are no such mistakes, then it should find the first unmatched opening bracket
without the corresponding closing bracket after it, like (in {}([]. If there are no mistakes,
you should output "No Mistakes".
2. If there exists a mistake then your program should output the index of the first
unmatched closing bracket in the input string, and if there are no unmatched closing
brackets, output the index of the first unmatched opening bracket in the input string.
Note: In case of unmatched brackets you will always look for the first unmatched
closing bracket, if there are no unmatched closing brackets, then you will look for the
first unmatched opening bracket.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7b9469f3-75d7-4a0e-bec6-2ca8135966e0%2F4367aa9e-cd5c-4662-a646-fdd88b2d413c%2F9mcyyis_processed.png&w=3840&q=75)

Step by step
Solved in 2 steps









