• Home
  • About
    • Ryureka Moment photo

      Ryureka

      Sin Prisa, Sin Pausa

    • About Me
    • Facebook
    • Github
    • Youtube
  • Projects
  • Posts
    • Posts
    • ProblemSolvings
    • Tags
    • Blog
    • Examples
  • ProblemSolving
    • ProblemSolving
    • BOJ
    • Programmers
    • SWEA
    • LeetCode
  • FrontEnd
    • FrontEnd
    • HTML
  • BackEnd
    • BackEnd
    • Server
      • Server
      • Spring
      • NodeJS
    • DataBase
      • DataBase
      • MySQL
      • MongoDB
  • Programming
    • Programming
    • Java
    • JS
    • Python
    • CleanCode
  • ComputerScience
    • DataStructure
    • Algorithm

[BOJ] 1759. 암호 만들기

15 Apr 2026

Reading time ~1 minute

  • 풀이

풀이

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int L=sc.nextInt();
		int C=sc.nextInt();
		
		char alpha[]=new char[C];
		
		for (int i = 0; i < alpha.length; i++) {
			alpha[i]=sc.next().charAt(0);
		}
		char pw[]=new char[L];
		Arrays.sort(alpha);
		
		go(0,pw,L,alpha,0);
		
		
	}
	
	public static void go(int index,char pw[],int L,char alpha[],int start) {
		if(index==L) {
			if(check(pw,L)) {
				for (int i = 0; i < L; i++) {
					System.out.print(pw[i]);					
				}
				System.out.println();
			}
			return;
		}
		
		for (int i = start; i < alpha.length; i++) {
			pw[index]=alpha[i];
			go(index+1,pw,L,alpha,i+1);
			pw[index]=' ';
		}
		
	}
	
	public static boolean check(char pw[],int L) {
		int cnt=0;
		for (int i = 0; i < pw.length; i++) {
			if(pw[i]=='a' || pw[i]=='e' || pw[i]=='i' || pw[i]=='o' || pw[i]=='u') {
				cnt++;
			}
		}
		if(cnt>=1 && L-cnt>=2) 
			return true;
		
		return false;
	}
}


백트래킹브루트포스조합 Share