백준 10775번 (그리디)
import java.util.Scanner;
public class problem182 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int size = in.nextInt();
boolean[] flag = new boolean[n];
boolean close = true;
int count = 0;
for (int j = 0; j < size; j++) {
int air = in.nextInt();
close = true;
for (int k = air - 1; k >= 0; k--) {
// 빈 게이트가 있는경우
if (flag[k] == false) {
close = false;
flag[k] = true;
count++;
// 비행기 한대당 게이트 한개를 들어갈수있음으로, break
break;
}
}
// 절대 도킹을 할수없는 경우 (맨 끝을 남겨놓는다)
if (close == true) {
break;
}
}
System.out.println(count);
}
}
백준 1105번 (그리디)
import java.util.Scanner;
public class problem183 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String st = in.nextLine();
String[] arr = st.split(" ");
char[] left = arr[0].toCharArray();
char[] right = arr[1].toCharArray();
int count = 0;
// 자릿수가 다르면 0
if (left.length == right.length) {
for (int i = 0; i < left.length; i++) {
// 자릿수 기준으로 같은지 확인, 8인지 확인
if (left[i] == right[i] && left[i] == '8') {
count++;
} else {
if (left[i] != right[i]) break;
}
}
}
System.out.print(count);
}
}