What's wrong with this code for htmltags lunchtime question

#include<bits/stdc++.h>

#define ll long long

#define INF 1e18

#define MOD 1000000007

#define nline “\n”

using namespace std;

int main(){

int t ;cin>>t;

while(t–){

fflush(stdin);

string s;

cin>>s;

int n=(int)s.length();

bool d=0;

if(s[0]!=’<’ || s[1]!=’/’ || s[n-1]!=’>’){

cout<<“Error”<<nline;

continue;

}

for(int i=2;i<s.length()-1;++i){

  if(  (s[i]<='9'   && s[i]>='0')  || ( s[i]<='z'  && s[i]>='a') ){

     d=true;  

  }else{

    d=false; 

  }

 

  if(!d){

    cout<<"Error"<<nline;

    break; 

  }

}



if(d){

  cout<<"Success"<<nline;

}

}

}

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

Edit:

Unscrambled it: Issue with HTMLTAGS problem - #4 by ssjgz

1 Like

Here is your code after formatting

#include<bits/stdc++.h>

#define ll long long

#define INF 1e18

#define MOD 1000000007

#define nline “\n”

using namespace std;

int main(){

int t ;cin>>t;

while(t–){

fflush(stdin);

string s;

cin>>s;

int n=(int)s.length();

bool d=0;

if(s[0]!=’<’ || s[1]!=’/’ || s[n-1]!=’>’){

cout<<“Error”<<nline;

continue;

}


for(int i=2;i<s.length()-1;++i){

  if(  (s[i]<='9'   && s[i]>='0')  || ( s[i]<='z'  && s[i]>='a') ){

     d=true;  

  }else{

    d=false; 

  }

 

  if(!d){

    cout<<"Error"<<nline;

    break; 

  }

}



if(d){

  cout<<"Success"<<nline;

}

}

}```

You missed this testcase when the body of html tag is empty :- 
1
</>
Your O/P:- 
Corret O/P :- Error

That’s still mangled in exactly the same way (try copy-and-pasting it and compiling it) :frowning:

1 Like

It is failing corner test case ig…
“</>” it should print “Error” write a condition for this…

yeah it worked :slight_smile: thankyou

It worked bro thanks

1 Like