티스토리 뷰
728x90
문제
https://www.acmicpc.net/problem/1759
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
풀이 및 소스코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static char[] tmp;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int l = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
tmp = new char[l];
char[] alph = new char[c];
alph = br.readLine().replaceAll(" ", "").toCharArray();
Arrays.sort(alph);
find_password(0, 0, 0, 0, l, c, alph);
System.out.println(sb);
}
public static void find_password(int start, int cnt, int cnt_m, int cnt_j, int l, int c, char[] alph) {
if(cnt == l) {
if(cnt_m>=1 && cnt_j>=2) {
for(int i=0;i<l;i++) {
sb.append(tmp[i]);
}
sb.append("\n");
}
return;
}
for(int i=start;i<c;i++) {
tmp[cnt] = alph[i];
if(alph[i]=='a'||alph[i]=='e'||alph[i]=='i'||alph[i]=='o'||alph[i]=='u') {
find_password(i+1, cnt+1, cnt_m+1, cnt_j, l, c, alph);
}else {
find_password(i+1, cnt+1, cnt_m, cnt_j+1, l, c, alph);
}
}
}
}
반응형
'Coding - Algo > Java' 카테고리의 다른 글
[SWEA] 7465:창용 마을 무리의 개수 (Java 자바) (0) | 2021.08.24 |
---|---|
[SWEA] 3289:서로소 집합 (Java 자바) (0) | 2021.08.24 |
[백준] 2605번:줄 세우기 (Java 자바) (0) | 2021.08.23 |
[백준] 2309번:일곱 난쟁이 (Java 자바) (0) | 2021.08.23 |
[SWEA] 1238:Contact (Java 자바) (0) | 2021.08.23 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- swea 타일링
- poker swea
- SSAFY
- 파이썬
- 파이썬 풀이
- 백준 17144
- swea 4070 타일링
- 프로그래머스 파이썬
- swea 1240 자바
- swea 타일링 자바
- union-find
- yoloV3
- 백준
- 백준 풀이
- 메뉴리뉴얼 풀이
- ubuntu
- 백준파이썬
- 백준 dp 문제
- 1699 자바
- 프로그래머스 자바
- 우분투
- 3996 자바
- 프로그래머스
- 삼성청년SW아카데미
- SWEA
- 1240 자바
- 타일링 자바
- 더 맵게
- swea 1240
- 프로그래머스 더 맵게
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함