ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1654. Cipher Message

WA2
Posted by DenisBordachkov 15 Feb 2019 02:29
Why Wring answer?
import java.util.Scanner;

public class T1654 {
    public static char[] arr;
    public static String out = "";
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        String inp = sc.next();
        sc.close();
        arr = new char[inp.length()];
        arr = inp.toCharArray();
        format();
        if(out != "") {
            System.out.println(out);
        } else {
            System.out.println("");
        }

    }

    public static void format() {
        boolean isFormat = false;
        int l = arr.length;
        for(int i = 0; i< l-1; i++) {
            if(arr[i] == arr[i+1]) {
                arr[i] = 0;
                arr[i+1] = 0;
                isFormat = true;
                } else if(arr[i] != arr[i+1] & arr[i] != 0){
                out += arr[i];
            }
        }
        out+= arr[arr.length-1];
        if(isFormat == true) {
            arr = new char[out.length()];
            arr = out.toCharArray();
            out = "";
            format();
        }
    }

}