https://www.acmicpc.net/problem/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
|
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.lang.StringBuilder
val br = BufferedReader(InputStreamReader(System.`in`))
val bw = BufferedWriter(OutputStreamWriter(System.out))
val input = readLine()!!.split(" ").map{it.toInt()}
val n = input[0]
val c = input[1]
var key = mutableListOf<String>()
var str = mutableListOf<String>()
val ans = mutableListOf<String>()
fun main()=with(br){
val line = readLine()!!.split(" ")
key = line.sortedBy { it }.toMutableList()
//println(key)
makeRandom(0,0)
//println(ans)
for(i in 0 until ans.size){
var moum = 0
var jaum = 0
for(j in ans[i]){
if(j=='a' || j=='e' || j=='i' || j=='o' || j=='u'){
moum++
}
else{
jaum++
}
}
if(moum>=1 && jaum>=2){
bw.write("${ans[i]}\n")
}
}
bw.flush()
bw.close()
}
fun makeRandom(index:Int,cnt:Int){
if(cnt==n){
var sb = StringBuilder()
for(i in 0 until str.size){
sb.append(str[i])
}
ans.add(sb.toString())
return
}
for(i in index until c){
str.add(key[i])
makeRandom(i+1,cnt+1)
str.removeLast()
}
}
|
cs |
'알고리즘 공부 > 백트레킹' 카테고리의 다른 글
백준 치킨배달 15686번 with Kotlin (0) | 2021.09.05 |
---|---|
백준 15666번 N과M(12) with Kotlin (0) | 2021.08.26 |
백준 15663번 N과M (9) with Kotlin (0) | 2021.08.26 |
백준 15657번 with Kotlin N과M(8) (0) | 2021.08.26 |
백준 15654번 with Kotlin N과M(5) (0) | 2021.08.26 |