hacker rank 24th problem(tag content extr...)

24. tag content extractor

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution{
public static void main(String[] args){

Scanner in = new Scanner(System.in);
int testCases = Integer.parseInt(in.nextLine());
while(testCases>0){
String line = in.nextLine();
String regex = "<([^<>]+)>([^<]+)</\\1>";//this is a regax expression
      //hard to write but easy stuff at all
Pattern p = Pattern.compile(regex);//this cheks that the statement we added is right or not
Matcher m = p.matcher(line);
if(!m.find()) {
  System.out.println("None");
} else {
  do {
    System.out.println(m.group(2));
  } while(m.find());
}
         

testCases--;
}
}
}


Compiler Message
Success
Input (stdin)Download
4
<h1>Nayeem loves counseling</h1>
<h1><h1>Sanjay has no watch</h1></h1><par>So wait for a while<par>
<Amee>safat codes like a ninja</amee>
<SA premium>Imtiaz has a secret crash</SA premium>
Expected OutputDownload
Nayeem loves counseling
Sanjay has no watch
None
Imtiaz has a secret crash{-truncated-}
Download to view the full testcase

Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions