Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Binary Search
- SQL
- array
- Class
- implement
- sorting
- Math
- Binary Tree
- Number Theory
- 코딩테스트
- string
- two pointers
- simulation
- 구현
- 자바
- java
- geometry
- Tree
- 파이썬
- bit manipulation
- greedy
- Stack
- hash table
- Method
- Matrix
- dynamic programming
- 코테
- Data Structure
- database
- Counting
Archives
- Today
- Total
코린이의 소소한 공부노트
[백준 온라인 저지] 10818. 최소, 최대 본문
- 입력: 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.
- 출력: 첫째 줄에 주어진 정수 N개의 최솟값과 최댓값을 공백으로 구분해 출력한다.
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.valueOf(br.readLine()), max, min;
if(n==1){
max = Integer.valueOf(br.readLine()); min = max;
} else{
String[] nums = br.readLine().split(" ");
max = Math.max(Integer.valueOf(nums[0]), Integer.valueOf(nums[1]));
min = Math.min(Integer.valueOf(nums[0]), Integer.valueOf(nums[1]));
for(int i=2 ; i<n ; i++){
if(Integer.valueOf(nums[i])>max) max = Integer.valueOf(nums[i]);
else if(Integer.valueOf(nums[i])<min) min = Integer.valueOf(nums[i]);
}
}
System.out.println(min + " " + max);
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 5597. 과제 안 내신 분..? (0) | 2023.03.17 |
---|---|
[백준 온라인 저지] 2562. 최댓값 (0) | 2023.03.17 |
[백준 온라인 저지] 10871. X보다 작은 수 (0) | 2023.03.17 |
[백준 온라인 저지] 10807. 개수 세기 (0) | 2023.03.17 |
[백준 온라인 저지] 10988. 팰린드롬인지 확인하기 (0) | 2023.03.17 |