@@ -0,0 +1,2100 @@
+package java_problems.strings;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0Aimport java.util.regex.Matcher;%0D%0Aimport java.util.regex.Pattern;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * When we write something, it is easy to repeat words by mistake. For example:%0D%0A * Monmoy loves to to code. Here, %22to%22 is written multiple times.%0D%0A * %0D%0A * Using Regex, we can easily identify the repeated pattern in a given text. In%0D%0A * this problem, you will be given a text. Your task is to identify the%0D%0A * consecutively repeated words and delete them after the first occurrence of%0D%0A * the word.%0D%0A * %0D%0A * Complete the code in the editor to solve this problem. Don't modify any extra%0D%0A * lines. You will get the wrong answer if you modify more than 3 lines.%0D%0A * %0D%0A * Input Format: %0D%0A * The first line of input contains an integer N, representing the number of%0D%0A * testcases. The next N lines contain a string of English letters and%0D%0A * whitespaces.%0D%0A * %0D%0A * Constraints: %0D%0A * In each line, there will be at most 104 English letters and whitespaces.%0D%0A * %0D%0A * 1 %3C= N %3C= 100%0D%0A * %0D%0A * Output Format: %0D%0A * Print the input string after deleting the consecutive words after the first%0D%0A * occurrence of the word.%0D%0A * %0D%0A * Sample Input: %0D%0A * 4%0D%0A * Goodbye bye bye world world world%0D%0A * Swapnil went went to to to his business%0D%0A * Rana is is the the best player in eye eye game%0D%0A * in inthe%0D%0A * %0D%0A * Sample Output: %0D%0A * Goodbye bye world%0D%0A * Swapnil went to his business%0D%0A * Rana is the best player in eye game%0D%0A * in inthe%0D%0A */%0D%0Apublic class JavaRegex2 %7B%0D%0A%09%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%0D%0A%09%09String pattern = %22%5C%5Cb(%5C%5CS+)(%5C%5Cs+(%5C%5C1))+%5C%5Cb%22;%0D%0A%09%09Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);%0D%0A%0D%0A%09%09Scanner in = new Scanner(System.in);%0D%0A%09%09int testCases = Integer.parseInt(in.nextLine());%0D%0A%09%09while (testCases %3E 0) %7B%0D%0A%09%09%09String input = in.nextLine();%0D%0A%09%09%09Matcher m = r.matcher(input);%0D%0A%09%09%09@SuppressWarnings(%22unused%22)%0D%0A%09%09%09boolean findMatch = true;%0D%0A%09%09%09while (m.find()) %7B%0D%0A%09%09%09%09input = input.replaceAll(m.group(), m.group(1));%0D%0A%09%09%09%09findMatch = false;%0D%0A%09%09%09%7D%0D%0A%09%09%09System.out.println(input);%0D%0A%09%09%09testCases--;%0D%0A%09%09%7D%0D%0A%09%09in.close();%0D%0A%09%7D%0D%0A%7D

Add JavaRegex2