[알고리즘/백준] 10818 최소,최대(자바)

[알고리즘/백준] 10818 최소,최대(자바)

문제

https://www.acmicpc.net/problem/10818

풀이 코드

하나의 수를 입력 받을 때마다 즉시 비교

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { int num = Integer.parseInt(st.nextToken()); max = Math.max(max, num); min = Math.min(min, num); } System.out.println(min + " " + max); } }

728x90

from http://developer-hm.tistory.com/157 by ccl(A) rewrite - 2021-09-20 01:26:59