WA - Problem Code: COMPILER

Question Link—> COMPILER Problem - CodeChef

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
string str;
cin>>str;
// if(str==“–”)
// break;
stackst;
int k=0;
int count_balance=0;
//cout<<str.length();
for(int i =0;i<str.length();i++)
{
if(str[i]==‘<’)
k+=1;
else
k-=1;

		if(k<0)
		{
			count_balance=0;
			break;
		}
		if(k==0)
			{
				count_balance=i+1;

			}



	}
	while(!st.empty())
	{
		st.pop();
	}
	cout<<count_balance<<"\n";
	}
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

It fails for the sample testcase.

1 Like

Sorry my bad ! Now I have corrected it and the code is compiled successfully ! :slight_smile:

1 Like