-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_10818.java
More file actions
69 lines (61 loc) ยท 1.73 KB
/
_10818.java
File metadata and controls
69 lines (61 loc) ยท 1.73 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
package backjoon;
// https://www.acmicpc.net/problem/10818
// ์ต์, ์ต๋
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class _10818 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
// sol1 Mathํจ์ ์ฌ์ฉํ๊ธฐ
// memory 116352 runtime 420 -> br.close()ํ๋ฉด memory 116588 runtime 404
/*
int min = Integer.parseInt(st.nextToken());
int max = min;
for(int i=1; i<n; i++){ //i๊ฐ 0์ด ์๋ 1์ธ ์ด์ ๋ min, max ์ ์ธํ ๋ 5๊ฐ์ ์ซ์์ค ์ฒซ๋ฒ์งธ ํ ํฐ์ ์ฌ์ฉํ๊ธฐ๋๋ฌธ
int num = Integer.parseInt(st.nextToken());
min = Math.min(min, (num));
max = Math.max(max, (num));
}
br.close();
System.out.println(min+" "+max);
*/
// sol2 ๋ฐฐ์ด์ ๋ ฌ๋ก ํ๊ธฐ
// memory 114572 runtime 1000 -> br.close()ํ๋ฉด memory 115624 runtime 1016
/*
int i = 0;
int[] arr = new int[n];
while(st.hasMoreTokens()) {
arr[i] = Integer.parseInt(st.nextToken());
i++;
}
Arrays.sort(arr);
System.out.println(arr[0] + " " + arr[n-1]);
*/
// sol3 ๋ฐฐ์ด์์ด ๋ฐ์ ๋ฌธ์ ์ฆ์ ๋น๊ตํ๊ธฐ
// memory 107004 runtime 472
int max = -1000001;
int min = 1000001;
while(st.hasMoreTokens()) {
int val = Integer.parseInt(st.nextToken());
if(val>max) {
max = val;
}
if(val<min) {
min = val;
}
}
System.out.println(min + " " + max);
}
}
/*
input
5
20 10 35 30 7
output
7 35
*/