|
|
back to boardWA2 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(); } } } |
|
|