MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

GeeksForGeeks/Parenthesis_Checker/Solution.cpp:16–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16int main()
17{
18 int t; // t is no of test cases
19 cin>>t;
20 while(t--)
21 {
22 string s;
23 cin>>s;
24 stack<char> st; // declare stack st
25 for(int i=0;i<s.length();i++) // iterate through the string
26 {
27 if(!st.empty() && areMatchingBrackets(st.top(),s[i])) //If the current character is a closing bracket (‘)‘ or ‘}‘ or ‘]‘) then check if it is matching bracket.
28 st.pop(); // if matching bracket then pop from the stack
29 else
30 st.push(s[i]); // If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.
31 }
32 if(st.empty())
33 cout<<"balanced"<<endl;
34 else
35 cout<<"not balanced"<<endl;
36 }
37
38 return 0;
39}

Callers

nothing calls this directly

Calls 1

areMatchingBracketsFunction · 0.85

Tested by

no test coverage detected