반응형



1. Scanner를 이용한 방법
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int xmax = -10000;
int xmin = 10000;
int ymax = -10000;
int ymin = 10000;
for(int i=0; i<N; i++){
int x = sc.nextInt();
int y = sc.nextInt();
xmax = Math.max(xmax, x);
xmin = Math.min(xmin, x);
ymax = Math.max(ymax, y);
ymin = Math.min(ymin, y);
}
System.out.println((xmax-xmin)*(ymax-ymin));
sc.close();
}
}
2. BufferedReader를 이용한 방법
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 xmax = -10000;
int xmin = 10000;
int ymax = -10000;
int ymin = 10000;
for(int i=0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
xmax = Math.max(xmax, x);
xmin = Math.min(xmin, x);
ymax = Math.max(ymax, y);
ymin = Math.min(ymin, y);
}
System.out.println((xmax-xmin)*(ymax-ymin));
br.close();
}
}반응형
'알고리즘 > 백준' 카테고리의 다른 글
| [백준] 14215 - 세 막대 (JAVA/ 자바) (0) | 2024.04.16 |
|---|---|
| [백준] 5073 - 삼각형과 세 변 (JAVA/ 자바) (2) | 2024.04.15 |
| [백준] 15894 - 수학은 체육과목 입니다. (JAVA/ 자바) (0) | 2024.04.13 |
| [백준] 3009 - 네번째 점 (JAVA/ 자바) (0) | 2024.04.12 |
| [백준] 1085 - 직사각형에서 탈출 (JAVA/ 자바) (0) | 2024.04.11 |