Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

forDevLife

[이코테]숫자 카드 게임 <그리디> 본문

알고리즘

[이코테]숫자 카드 게임 <그리디>

JH_Lucid 2021. 5. 1. 16:03
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);
    }
}
Comments