Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <stack>
- int main() {
- //code
- int tc = 0;
- // std::stack<char> opex;
- cin>>tc;
- char c = '{';
- char& tmp = c;
- char top = '{';
- if (tmp == top)
- cout<<"same";
- else
- cout<<"not same";
- // std::string exp;
- // std::string::iterator it;
- while (tc > 0)
- {
- tc--;
- std::stack<char> opex;
- //cin>>tc;
- std::string exp;
- std::string::iterator it;
- cin>>exp;
- cout<<"input is "<<exp;
- char top,tmp;
- for (it = exp.begin(); it!=exp.end();it++)
- {
- if (*it == '[' || *it == '{' || *it == '(')
- {
- cout<<"pushing"<<"n";
- opex.push((char)*it);
- }
- else
- {
- top = opex.top();
- //opex.pop();
- tmp = *it;
- cout<<"top is "<<top<<" tmp is "<<tmp<<"n";
- if (top == tmp)
- {
- cout<<"same"<<"n";
- //break;
- }
- else
- {
- cout<<"not same"<<"n";
- break;
- }
- opex.pop();
- //cout<<"looping";
- }
- }
- if (opex.empty())
- cout<<"balanced"<<"n";
- else
- {
- cout<<"not balanced"<<"n";
- while (!opex.empty())
- opex.pop();
- }
- }
- return 0;
Add Comment
Please, Sign In to add comment