🤜 코테/알고리즘
이코데 그리디 문제
wnwlals13
2021. 2. 19. 12:58
숫자 카드 게임
import java.util.*;
public class Main {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int result = 0;
for (int i = 0 ; i < n ; i ++) {
int min_value = 10001;
for ( int j=0 ; j < m ; j++) {
int x = sc.nextInt();
//현재 줄에서 가장 작은 수 찾기
min_value = Math.min(min_value, x);
}
//가장 작은 수 중에서 큰 수 찾기
result = Math.max(result, min_value);
}
System.out.println(result);
}
}
a, b 둘 중 최댓값 구하기 : Math.max(a, b);
a, b 둘 중 최솟값 구하기 : Math.min(a, b);
1이 될 때까지
import java.util.*;
public class Main {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int cnt = 0;
cnt += (n%k);
while ( n > 1) {
n = (n / k);
cnt += 1;
}
System.out.println(cnt);
}
}