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--;
}
}
}
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--;
}
}
}
Comments