백준(Java)/23년 11월
[Java] 백준 - 1759번: 암호 만들기
C0MPAS
2023. 11. 23. 15:09
11월 23일(목) - 브루트포스 (1759번)
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
문제점
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
풀이
(풀이출처 -> https://yoon990.tistory.com/32)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static int L,C;
public static char[] inputs;
public static char[] pwd;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
L = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
inputs = new char[C];
pwd = new char[L];
for(int i=0; i<C; i++)
{
inputs[i] = st.nextToken().charAt(0);
}
Arrays.sort(inputs);
combination(0, 0);
}
public static void combination(int count, int start){
if(count == L)
{
if(check(pwd))
{
for(char c : pwd)
{
System.out.print(c);
}
System.out.println();
};
return;
}
for(int i=start; i<C; i++)
{
pwd[count] = inputs[i];
combination(count+1, i+1);
}
}
public static boolean check(char[] pwd){
int j = 0;
int m = 0;
for(int i=0; i< pwd.length; i++)
{
if(pwd[i] == 'a' || pwd[i] == 'e' || pwd[i] == 'i' || pwd[i] == 'o' || pwd[i] == 'u')
{
m++;
}
else
{
j++;
}
}
if(j >= 2 && m >= 1)
{
return true;
}
else
{
return false;
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ