Java Regex 2 - Duplicate Words

Sort by

recency

|

398 Discussions

|

  • + 0 comments

    Test case 0

    Test case 1

    Test case 2

    Test case 3

    Test case 4

    Test case 5

    Test case 6 Compiler Message Wrong Answer Input (stdin) 5 Goodbye bye bye world world world Sam went went to to to his business Reya is is the the best player in eye eye game in inthe Hello hello Ab aB Expected Output Goodbye bye world Sam went to his business Reya is the best player in eye game how to so

  • + 0 comments

    import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern;

  • + 0 comments

    Has anyone faced the problem that code does not print to stdout even though it does in local machine? here is my code

            try (Scanner aScanner = new Scanner(System.in)){
                int num = aScanner.nextInt();
                List<String> linesAfterDeduplication = new LinkedList<>();
                for (int i = 0; i <= num; i++) {
                    String line = aScanner.nextLine().trim();
                    Matcher matcher = pattern.matcher(line);
                    while (matcher.find()) {
                        line = line.replace(matcher.group(0), matcher.group(1));
                    }
                    linesAfterDeduplication.add(line);
                }
    
                for (String line : linesAfterDeduplication) {
                    System.out.println(line);
                }
            }
    
  • + 0 comments

    The instruction are incomprehensible. I cannot even get the custom checker to run my code.

  • + 0 comments

    String regex = "(?iu)\b(\w+)\b(?:\s+\1\b)+"; Pattern p = Pattern.compile(regex);

        Scanner in = new Scanner(System.in);
        int numSentences = Integer.parseInt(in.nextLine());
    
        while (numSentences-- > 0) {
            String input = in.nextLine();
    
            Matcher m = p.matcher(input);
    
            // Check for subsequences of input that match the compiled pattern
            while (m.find()) {
                input = input.replaceAll(regex, "$1");
            }
    
            // Prints the modified sentence.
            System.out.println(input);
        }
    
        in.close();