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.
Here are two codes that work correctly in the ide I use, but this site does not accept the answer.
import java.util.*;
public class Soru {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
in.nextLine();
for (int i = 0; i < num; i++) {
String str= in.nextLine();
String[] array=str.split(" ");
Set<String> seen = new LinkedHashSet<>();
for (String word : array) {
String lowerCaseWord = word.toLowerCase();
if (!seen.contains(lowerCaseWord)) {
seen.add(word);
}
}
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num =in.nextInt();
in.nextLine();
while (num-- > 0) {
String input = in.nextLine();
String regex = "\\b(\\w+)(\\s+\\1\\b)+";
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(input);
while (m.find()) {
input = input.replaceAll(m.group(), m.group(1));
}
System.out.println(input);
}
}
}
System.out.println(String.join(" ", seen));
}
}
}
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 →
Here are two codes that work correctly in the ide I use, but this site does not accept the answer.
import java.util.*;
public class Soru { public static void main(String[] args) {
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int num =in.nextInt(); in.nextLine();
}
}