What is the bug in my solution? question
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
bool found = 0;
int length = 0, count = 0, opened=0,valid = 0;
int xmax = 0;
for(int i=0; i<s.size(); ++i)
{
if(opened==0 && s[i]=='>')
{
break;
}
if(s[i]=='<')
{
found = 1;
opened++;
}
if(found && opened>0)
{
if(s[i]=='>')
{
length+=2;
opened--;
}
}
if(opened==0)
{
count+=length;
xmax = max(xmax,count);
found =0;
length=0;
valid = 1;
}
}
if(valid)
cout<<xmax<<endl;
else
cout<<0<<endl;
}
}