-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from AlgorithmWithMe/byeonghee/8week
[소병희] 창고 다각형, 색종이 만들기, 단축키 지정, 쇠막대기, 문자열 집합
- Loading branch information
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |