풀이)
입력된 숫자를 만들기 위해 필요한 최소한의 숫자 세트 수는?
입력받은 숫자들의 각 개수를 센다.
예를 들어 11123 은 1이 3개, 2가 1개, 3이 1개...
int count[10] 에 대해 count[1] = 3, count[2] =1, count[3] = 1 ... 식으로 숫자를 넣고, 그 중 가장 큰 수를 구하면 된다.
이 때 6과 9는 뒤집어 쓸 수 있으므로,
(count[6] + count[9]) / 2 해서 수를 구하면 된다.
내 코드)
import java.io.*;
public class Backjoon1475 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String []temp = bf.readLine().split("");
int input[] = new int[temp.length];
for(int i=0;i<temp.length;i++) {
input[i] = Integer.parseInt(temp[i]);
}
int count[] = new int[10];
for(int i=0;i<input.length;i++) {
int num = input[i];
count[num]++;
}
if(count[6] + count[9] > 1) {
int sum = count[6] + count[9];
if(sum%2 == 0) {
count[6] = sum/2;
count[9] = sum/2;
}else{
count[6] = sum/2;
count[9] = sum/2 + 1;
}
}
int max = 0;
for(int i=0;i<count.length;i++) {
if(max < count[i]) {
max = count[i];
}
}
System.out.println(max);
}
}