답변 2
0
package main;
import java.util.Scanner;
public class Main {
public String solution(String str) {
String answer = "";
str = str + " ";
int cnt = 1;
for (int i = 0; i < str.length() - 1; i++) {
if(str.charAt(i) == str.charAt(i+1)) cnt++;
else {
answer += str.charAt(i);
if(cnt > 1) {
answer += cnt;
cnt = 1;
}
}
}
return answer;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
Main T = new Main();
for (char c : T.solution(str).toCharArray()) {
System.out.print(c + " ");
}
}
}