Why am i getting Wrong Answer Can someone help me out ?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int x = 1;
while(x <= t)
{
string s;
cin>>s;
stack <char> st;
for(int i = 0;i<s.size();i++)
{
if(st.empty())
{
st.push(s[i]);
}
else
{
if(s[i] == '}')
st.pop();
else if(s[i] == '{')
st.push(s[i]);
}
}
// if(st.size() > 0)
// {
string temp = "";
while(!st.empty())
{
temp += st.top();
st.pop();
}
reverse(temp.begin(),temp.end());
//cout<<temp<<endl;
// cout<<endl;
int p1 = 0;
int p2 = 1;
int c = 0;
while(p1 < p2 and p2 < s.size())
{
if(temp[p1] == '}' and temp[p2] == '{')
c += 2;
else if(temp[p1] == '{' and temp[p2] == '}')
c += 0;
else if(temp[p1] == '{' and temp[p2] == '{')
c += 1;
else if(temp[p1] == '}' and temp[p2] == '}')
c += 1;
p1 ++, p2 ++;
}
cout<<x<<". "<<c<<endl;
// else
// cout<<0<<endl;
x++;
}
return 0;
}