-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1181.java
More file actions
76 lines (69 loc) ยท 1.42 KB
/
_1181.java
File metadata and controls
76 lines (69 loc) ยท 1.42 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package backjoon;
// https://www.acmicpc.net/problem/1181
// ๋จ์ด ์ ๋ ฌ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
public class _1181 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// memory 28808 runtime 288
int N = Integer.parseInt(br.readLine());
// ๋ฐฐ์ด์ ๋ฃ๊ธฐ
String[] arr = new String[N];
for (int i = 0; i < N; i++) {
arr[i] = br.readLine();
}
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
// ๋จ์ด ๊ธธ์ด๊ฐ ๊ฐ์ผ๋ฉด ์ฌ์ ์
if(o1.length() == o2.length()){
return o1.compareTo(o2);
} else{
return o1.length() - o2.length(); //๊ธธ์ด์ฐจ๊ฐ ์์๋ฉด ์๋ฆฌ๊ฐ ๋ฐ๋๊ณ , ์์๋ฉด ๊ทธ๋๋ก
}
}
});
StringBuilder sb = new StringBuilder();
//์ค๋ณต๋๋ ๋จ์ด๋ ๋นผ๊ณ ์ถ๋ ฅํ๊ธฐ์ํด ๋น๊ต๋ฅผ ์ํด ์ฒซ๋ฒ์งธ ๋จ์ด๋ฅผ ๋ฃ์ด๋
sb.append(arr[0]).append("\n");
for(int i=1; i<N; i++){
if(!arr[i].equals(arr[i-1])){
sb.append(arr[i]).append("\n");
}
}
System.out.println(sb);
}
}
/*
input
13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours
output
i
im
it
no
but
more
wait
wont
yours
cannot
hesitate
*/