TitanYang's Programming
[JAVA 순환 알고리즘] 백준 알고리즘 1759번 / 암호 만들기 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | package baekjoon; import java.util.Scanner; import java.util.Arrays; class makePassword{ int n,m; char[] origin; makePassword(char[] a,int n, int m){ this.origin=a; this.n=n; this.m=m; Arrays.sort(origin); } void make(String s, int t) { if(t==m)return; s=s+origin[t]; //System.out.println(s); if(s.length()==n) { int cntJ=0; int cntM=0; for(int i=0;i<n;i++) { if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u') { cntM++; }else cntJ++; } if(cntM>=1&&cntJ>=2)System.out.println(s); return; }else { for(int i=t+1;i<=m;i++) { make(s,i); } } } } /** * * @Package : baekjoon * @FileName : makePasswordEx.java * @Author : Yang TaeIl * @date : 2018. 2. 15. * */ public class makePasswordEx { /** * * * @Method Name : main * @param args */ public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); char[]a=new char[m]; for(int i =0;i<m;i++) { a[i]=sc.next().charAt(0); } makePassword b= new makePassword(a,n,m); for(int i=0;i<=m-n;i++) { b.make("", i); } } } | cs |
주어진 규칙에 맞는 암호의 모든 경우의 수를 출력하는 알고리즘을 짜는 문제입니다.
일단 가능한 경우를 만들고 주어진 조건을 만족하는지 확인하여 출력여부를 결정하였습니다.
'JAVA' 카테고리의 다른 글
[JAVA 순환 알고리즘] 백준 알고리즘 1456번 / 거의소수 찾기 (0) | 2018.03.08 |
---|---|
[JAVA 순환 알고리즘] 백준 알고리즘 1074번 / Z탐색알고리즘 (0) | 2018.02.27 |
[JAVA 순환 알고리즘] 백준 알고리즘 4811번 / 알약 (0) | 2018.02.27 |
[JAVA 기본 알고리즘] 백준 알고리즘 2747번 / 피보나치 수 (0) | 2017.08.22 |
[JAVA 기본 알고리즘] 백준 알고리즘 2455번 / 지능형 기차 (0) | 2017.08.22 |