Skip to content

Commit

Permalink
Merge pull request #37 from AlgorithmWithMe/byeonghee/8week
Browse files Browse the repository at this point in the history
[소병희] 창고 다각형, 색종이 만들기, 단축키 지정, 쇠막대기, 문자열 집합
  • Loading branch information
bngsh authored Nov 8, 2022
2 parents 5d21d27 + fb1523b commit 0ee8aa6
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/kotlin/byeonghee/8week/단축키 지정.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package byeonghee.`8week`

import java.io.*

class `소병희_단축키 지정` {

val br = BufferedReader(InputStreamReader(System.`in`))
val keySet = HashSet<Char>()

fun solution() {
val n = br.readLine().toInt()

repeat(n) {
br.readLine().let { words ->
words.split(" ").firstOrNull { word ->
keySet.add(word[0].lowercaseChar())
}?.let { key ->
println(words.replaceFirst(key, "[${key[0]}]${key.drop(1)}"))
} ?: words.replace(" ", "").firstOrNull { char ->
keySet.add(char.lowercaseChar())
}?.let { key ->
println(words.replaceFirst("$key", "[$key]"))
} ?: println(words)
}
}
}
}

fun main() {
`소병희_단축키 지정`().solution()
}
28 changes: 28 additions & 0 deletions src/main/kotlin/byeonghee/8week/문자열 집합.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package byeonghee.`8week`

import java.io.*

class `소병희_문자열 집합` {

val br = BufferedReader(InputStreamReader(System.`in`))
val hashMap = HashMap<String, Boolean>()
var answer = 0

fun solution() {
val (n, m) = br.readLine().split(" ").map{ it.toInt() }

repeat(n) {
hashMap[br.readLine()] = true
}

repeat(m) {
if (hashMap[br.readLine()] != null) answer++
}

println(answer)
}
}

fun main() {
`소병희_문자열 집합`().solution()
}
47 changes: 47 additions & 0 deletions src/main/kotlin/byeonghee/8week/색종이 만들기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package byeonghee.`8week`

import java.io.*

class `소병희_색종이 만들기` {

data class Pos(val r: Int, val c: Int)

val br = BufferedReader(InputStreamReader(System.`in`))
lateinit var paper : Array<IntArray>
var white = 0
var blue = 0

fun solution() {
val n = br.readLine().toInt()
paper = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() }

quadTree(Pos(0, 0), n)
println(white)
println(blue)
}

fun quadTree(p: Pos, l: Int) {
var count = 0
for(r in p.r until p.r + l) for(c in p.c until p.c + l) {
if (paper[r][c] == 0) count++
}
if (count == l * l) {
white++
return
}
else if (count == 0) {
blue++
return
}

val nxtL = l / 2
quadTree(p, nxtL)
quadTree(Pos(p.r + nxtL, p.c), nxtL)
quadTree(Pos(p.r, p.c + nxtL), nxtL)
quadTree(Pos(p.r + nxtL, p.c + nxtL), nxtL)
}
}

fun main() {
`소병희_색종이 만들기`().solution()
}
32 changes: 32 additions & 0 deletions src/main/kotlin/byeonghee/8week/쇠막대기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package byeonghee.`8week`

import java.io.*

class 소병희_쇠막대기 {

val br = BufferedReader(InputStreamReader(System.`in`))
var answer = 0
var acc = 0

fun solution() {
val brackets = br.readLine().toCharArray()

for(i in 1 until brackets.size) {
if (brackets[i] == '(' && brackets[i-1] == '(') acc++
else if (brackets[i] == ')') {
if (brackets[i-1] == '(') {
answer += acc
}
else if (brackets[i-1] == ')') {
answer++
acc--
}
}
}
println(answer)
}
}

fun main() {
소병희_쇠막대기().solution()
}
44 changes: 44 additions & 0 deletions src/main/kotlin/byeonghee/8week/창고 다각형.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package byeonghee.`8week`

import java.io.*
import java.util.PriorityQueue

class `소병희_창고 다각형` {

data class Pillar(val d: Int, val h: Int)

val br = BufferedReader(InputStreamReader(System.`in`))
val pq = PriorityQueue(Comparator<Pillar>{ a, b -> b.h - a.h })
val storage = ArrayDeque<Pillar>()
var answer = 0

fun solution() {
val n = br.readLine().toInt()
repeat(n) {
br.readLine().split(" ").map{ it.toInt() }.let {
pq.add(Pillar(it[0], it[1]))
}
}
storage.add(pq.poll())

while(pq.isNotEmpty()) {
pq.poll().let { cur ->
if (cur.d < storage.first().d) {
answer += cur.h * (storage.first().d - cur.d)
storage.addFirst(cur)
}
else if (cur.d > storage.last().d) {
answer += storage.last().h + cur.h * (cur.d - storage.last().d - 1)
storage.addLast(cur)
}
}
}
answer += storage.last().h

println(answer)
}
}

fun main() {
`소병희_창고 다각형`().solution()
}

0 comments on commit 0ee8aa6

Please sign in to comment.