Софтуерно Инженерство
Loading...
+ Нов въпрос
Samuilow10eddy avatar Samuilow10eddy 4 Точки

06. Replace Repeating Chars - Text Processing Exercises

Здравейте, колеги може ли малко помощ, 80/100 проблема е в първия вход.

https://pastebin.com/NSZMXg1R

6.Replace Repeating Chars

Write a program that reads a string from the console and replaces any sequence of the same letters with a single corresponding letter.

Examples

Input

Output

aaaaabbbbbcdddeeeedssaa

abcdedsa

qqqwerqwecccwd

qwerqwecwd

Тагове:
0
Fundamentals Module 17/11/2019 12:53:14
willystyle avatar willystyle 1297 Точки
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ReplaceRepeatingChars {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] ch = scanner.nextLine().toCharArray();
        List<Character> characterList = new ArrayList<>();
        for (int i = 0; i < ch.length; i++) {
            characterList.add(ch[i]);
        }

        for (int i = 1; i < characterList.size(); i++) {
            char previous = characterList.get(i - 1);
            char current = characterList.get(i);

            if (previous == current){
                characterList.remove(i);
                i--;
            }
        }
        for (Character character : characterList) {
            System.out.print(character);
        }
    }
}

 

0