HTML Tags Codechef Solution

HTML Tags Solution Problem Code: HTMLTAGS

In addition to CP, Chef recently developed an interest in Web Development and started learning HTML. Now he wants to create his own HTML Code Editor. As a subproblem, he wants to check if a typed HTML closing tag has correct syntax or not.

A closing HTML tag must:

  • Start with "</"
  • End with ">"
  • Have only lower-case alpha-numeric characters as its body (between "</" and ">"). That is, each character of the body should either be a digit or a lower-case English letter.
  • Have a non-empty body.

Help Chef by printing "Success" if the tag is fine. If not, print "Error".

Input

  • The first line contains an integer TT, the number of test cases. Then TT test cases follow.
  • Each test case is a single line of input, a string describing the tag we need to check.

Output

For each test case, output in a single line, "Success" if it is a valid closing tag and "Error" otherwise (without quotes).

You may print each character of the string in uppercase or lowercase (for example, the strings "SuccEss""success""Success""SUCCESS" et cetera will all be treated as identical).

Constraints

  • 1≤T≤10001≤T≤1000
  • 1≤1≤ length(Tag)length(Tag) ≤1000≤1000
  • The characters of the string belong to the ASCII range [33,126][33,126] (note that this excludes space.)

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input

5 
</h1>  
Clearly_Invalid  
</singlabharat>  
</5>  
<//aA>  

Sample Output

Success  
Error  
Success
Success
Error

Explanation

Test Cases 1,3,41,3,4: The tags follow all mentioned constraints.

Test Case 22: The tag doesn’t contain opening and closing symbols and also includes characters other than lower-case alpha-numeric characters in its body.

Test Case 55: The tag also includes an upper-case alpha-numeric character "A" and a non alpha-numeric character "/" in its body.

Program:

#include <iostream>
#include <cstring> 
using namespace std;

int main() {
	// your code goes her
	int t;
	cin>>t;
	while(t--){
	    string s;
	    cin>>s; 
	    int f=10; 
	    if(s.length()>=4 && s[0]=='<' && s[1]=='/' && s[s.length()-1]=='>'){
	        for(int i=2;i<s.length()-1;i++){
	           
	            if((s[i]>='0' && s[i]<='9') or (int(s[i])>=97 && int(s[i])<=122)){
	                continue;
	            }
	            else{
	                cout<<"Error\n";
	                f=5;
	                break; 
	            }
	        }
	        if(f==10){
	            cout<<"Success\n";
	        } 
	    } 
	    else{
	        cout<<"Error\n";
	    }
	    
	   
	}
	
	    
	return 0;
}

Weekly Contest 247

Biweekly Contest 55

June Long Challenge 2021 Solutions

March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS

Related :

Related :

Leave a Comment

twenty − 14 =