i mean when the user pressed Enter (empty string), the program goes to newline! like that you do not anything , so here is my full code.
Code:
#include<iostream>
#include<stack>
#include<string>
#include <vector>
#include <stdio.h>
using namespace std;
bool ArePair(char opening,char closing)
{
if(opening == '(' && closing == ')') return true;
else if(opening == '[' && closing == ']') return true;
return false;
}
bool checkBalanced(string st)
{
stack<char> S;
for(int i =0 ; i<st.length() ; i++)
{
if(st[i] == '(' || st[i] == '[')
S.push(st[i]);
else if(st[i] == ')' || st[i] == ']')
{
if( (S.empty() ) || !ArePair(S.top(),st[i]))
return false;
else
S.pop();
}
}
return S.empty() ? true:false ;
}
int main()
{
int n;
cin>>n;
string st;
vector<string> vct;
while(n!=0)
{
cin>>st;
if (st.empty())
{
//string is empty and Balanced
//n--;
}
else
{
if(checkBalanced(st))
vct.push_back("Yes");
else
vct.push_back("No");
n--;
}
}
for (int i=0 ; i<vct.size() ; i++)
cout << vct.at(i) << endl;
return 0;
}