We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is my answer, but why there is no output in hackerrank? I try to execute it using my IDE and it works fine. I even copy paste one of the answer in discussions but it does not show any output.
import java.io.*;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for(int i=0; i<n; i++){
String str = scanner.nextLine();
String myregex = "\\b(\\w+)\\b(\\s+\\b\\1\\b)+";
Pattern pattern = Pattern.compile(myregex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
while(matcher.find()){
str = str.replace(matcher.group(), matcher.group(1));
}
System.out.println(str);
}
scanner.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Regex 2 - Duplicate Words
You are viewing a single comment's thread. Return to all comments →
this is my answer, but why there is no output in hackerrank? I try to execute it using my IDE and it works fine. I even copy paste one of the answer in discussions but it does not show any output.
}