-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path210223_3.txt
43 lines (40 loc) · 1.21 KB
/
210223_3.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//15회 E-PPER 5번 문자열 압축
import java.io.*;
import java.util.*;
//프로그래머스에서는 main함수 및 입출력문이 필요하지 않습니다. 대신 solution함수만 작성하면 됩니다.
public class Main {
static String solution(String input){
String answer="";
String str[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<String> list2 = new ArrayList<String>();
for(int i=0; i<input.length(); i++){
if(input.charAt(i)=='0'){
list.add(0);
}else{
list.add(1);
}
}
int count=1;
for(int i=0; i<list.size(); i++){
if(i!=0&&list.get(i)==list.get(i-1)){
count++;
}else if(i!=0&&list.get(i)!=list.get(i-1)){
list2.add(str[count-1]);
count=1;
}
}
list2.add(str[count-1]);
if(input.charAt(0)=='1')
answer+="1";
for(int i=0; i<list2.size(); i++)
answer+=list2.get(i);
return answer;
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
String answer= solution(input);
System.out.println(answer);
}
}