forDevLife
[이코테]숫자 카드 게임 <그리디> 본문
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] arr = new int[N][M];
for(int i=0; i< N; i++) {
st = new StringTokenizer(br.readLine(), " ");
for(int j=0; j<M; j++) {
arr[i][j] = Integer.parseInt(st.nextToken());
}
}
int real = 0;
for(int i=0; i< N; i++) {
int answer = arr[i][0];
for(int j=0; j<M; j++) {
if(answer >= arr[i][j]) {
answer = arr[i][j];
}
}
if(answer > real) {
real = answer;
}
}
System.out.print(real);
}
}
- 이중 for문 하나 안에서 모두 해결
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] arr = new int[N][M];
int btw_large = 0;
for (int i = 0; i < N; i++) {
int min_value = Integer.MAX_VALUE;
st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < M; j++) {
arr[i][j] = Integer.parseInt(st.nextToken());
if(min_value > arr[i][j]) {
min_value = arr[i][j];
}
}
if(btw_large < min_value) {
btw_large = min_value;
}
}
System.out.println(btw_large);
}
}
'알고리즘' 카테고리의 다른 글
[이코테]모험가 길드 <그리디> (0) | 2021.05.03 |
---|---|
[이코테]1이 될 때까지 <그리디> (0) | 2021.05.03 |
[이코테]큰 수의 법칙 <그리디> (0) | 2021.05.01 |
[백준] 13305 - 주유소 (자바) (0) | 2021.05.01 |
[백준] 1541 - 잃어버린 괄호 (자바) (0) | 2021.04.30 |
Comments