ํญํ ํด์ฒด(9242๋ฒ)
Silver 4
#๊ตฌํ #๋ฌธ์์ด #ํ์ฑ
https://www.acmicpc.net/problem/9242
๋ฌธ์ ๋ด์ฉ
๋ฌธ์ ์ ๊ทผ
๋ณ ๊ธฐํธ(*)์ ๊ณต๋ฐฑ์ผ๋ก ์ด๋ฃจ์ด์ง ์ซ์๊ฐ ์ ๋ ฅ๋๋ค.
์ซ์๋ 7 segment ์ซ์ ํ๊ธฐ๋ฒ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์๋ค.
๊ทธ๋ฅ ์ซ์๋ฅผ ํ์ฑ ํด์ 6์ผ๋ก ๋๋์ด ๋จ์ด์ง๋ฉด beer๋ฅผ ์ถ๋ ฅํ๊ณ ๊ทธ๋ ์ง ์์ผ๋ฉด boom์ ์ถ๋ ฅํ๋ฉด ๋๋ ๊ฐ๋จํ ๋ฌธ์ ์ด๋ค.
๋ํ ์ํธ๊ฐ ๋ฌด์กฐ๊ฑด 7 segment์ ์ซ์๋ค๋ง ๋์ค๋ ๊ฒ๋ ์๋๋ค.
์ํธ๋ 3 * 5์ ํํ๋ก 1์นธ์ฉ ๊ณต๋ฐฑ์ ๋๊ณ ์ฃผ์ด์ง๊ฒ ๋๋๋ฐ, 3 * 5์ ์ํธ ํ์์ ์งํค์ง ์์ ์ฝ๋๊ฐ ์ฌ ์ ๋ ์๋ค.
๊ทธ๋์ ์ 2๊ฐ์ง ์ํฉ์ ๋ง๋ ์ฒ๋ฆฌ(boom)๋ฅผ ํด์ฃผ์ด์ผ ํ๋ค.
๋ฌธ์ ํด๊ฒฐ ์ฝ๋
import java.io.BufferedReader
import java.io.InputStreamReader
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val codes = mutableListOf<List<String>>()
for (i in 0 until 5) {
val codeLine = readLine().map { it.toString() }
codes.add(codeLine)
}
try {
var codeParseResult = ""
val subCode = mutableListOf<List<String>>()
for (j in codes[0].indices) {
if (j % 4 == 0) {
for (k in 0 until 5) {
val subCodeLine = codes[k].subList(j, j + 3)
subCode.add(subCodeLine)
}
val res = parseCode(subCode)
codeParseResult += res
subCode.clear()
}
}
if (codeParseResult.toInt() % 6 == 0) println("BEER!!")
else println("BOOM!!")
} catch (e: Exception) {
println("BOOM!!")
}
}
private fun parseCode(compareValue: List<List<String>>): String {
val zero = listOf(
listOf("*", "*", "*"),
listOf("*", " ", "*"),
listOf("*", " ", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*"),
)
val one = listOf(
listOf(" ", " ", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*")
)
val two = listOf(
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf("*", "*", "*"),
listOf("*", " ", " "),
listOf("*", "*", "*"),
)
val three = listOf(
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf("*", "*", "*"),
)
val four = listOf(
listOf("*", " ", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*")
)
val five = listOf(
listOf("*", "*", "*"),
listOf("*", " ", " "),
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf("*", "*", "*"),
)
val six = listOf(
listOf("*", "*", "*"),
listOf("*", " ", " "),
listOf("*", "*", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*")
)
val seven = listOf(
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*"),
listOf(" ", " ", "*")
)
val eight = listOf(
listOf("*", "*", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*")
)
val nine = listOf(
listOf("*", "*", "*"),
listOf("*", " ", "*"),
listOf("*", "*", "*"),
listOf(" ", " ", "*"),
listOf("*", "*", "*")
)
return when (compareValue) {
zero -> "0"
one -> "1"
two -> "2"
three -> "3"
four -> "4"
five -> "5"
six -> "6"
seven -> "7"
eight -> "8"
nine -> "9"
else -> throw Exception("์ฌ๋ฐ๋ฅด์ง ์์ ์ซ์ ํ์")
}
}
๋ฌธ์ ํ์ด
์ฝ๋ ํ์์ด ํ ์ค์ 3๊ฐ์ ๋ฌธ์ ๋๋ ๊ณต๋ฐฑ๊ณผ 1๊ฐ์ ๊ณต๋ฐฑ์ด ๋ฐ๋ณต๋๋ ํ์์ด๊ธฐ ๋๋ฌธ์, ์ฝ๋์ ๋จ์ด์ ์ฒซ ๋ฒ์งธ ์ฐจ๋ก๊ฐ ๋๋ฉด ๋ฐ๋ณต์ผ๋ก ์ ๋ ฅ๋ฐ์ ์ฝ๋์ 3๊ฐ์ ๋จ์ด๋ฅผ 5๋ฒ ๋ฐ๋ณตํ๋ค.
์๋ฅผ ๋ค์ด ์ ๋ ฅ์ด ์๋์ ๊ฐ์ด ์ฃผ์ด์ง ๋,
*** * * * *** *** *** ***
* * * * * * * * *
* * * *** *** *** *** ***
* * * * * * * * *
*** * * *** *** *** ***
์๋์ ๊ฐ์ด ์ฝ๋ ๋จ์ด๋ฅผ 1๊ฐ์ฉ ๋ถ๋ฌ์ค๋ ๋ฐฉ์์ด๋ค.
***
* *
* *
* *
***
*
*
*
*
*
* *
* *
***
*
*
. . .
์๋์ ๊ฐ์ด ๋จ์ด๋ฅผ 1๊ฐ์ฉ ๋ถ๋ฌ์จ๋ค.
๊ทธ๋ฆฌ๊ณ ๋ถ๋ฌ์จ ๋จ์ด๋ฅผ 2์ค ๋ฆฌ์คํธ๋ก ์ ์ฅํ๊ณ , parseCode๋ฅผ ์ด์ฉํด ์ซ์๋ก ๋ณํํ๋ค.
parseCode์๋ 0๋ถํฐ 9๊น์ง์ 7 segment ์ซ์ ํ๊ธฐ๋ฒ ํํ๋ก ์ ์ํ ํ, ๋ค์ด์จ code์ ๊ฐ์ ์๊ฐ ์๋์ง ํ์ธํ๋ค.
0๋ถํฐ 9๊น์ง์ ์๊ฐ ๋ชจ๋ ํด๋น์ด ์ ๋๋ฉด ์ฌ๋ฐ๋ฅด์ง ์์ ์ฝ๋๊ฐ ์จ ๊ฒ์ด๋ค.
๊ทธ๋์ Exception์ throw ํด์ฃผ๊ณ parseCode ๋ก์ง์ try catch์์ ์งํํ๋ค.
catch๋ก ์จ ๊ฒฝ์ฐ์๋ parseCode์์ error๊ฐ ๋์ ธ์ง ์ํฉ์ ์ค๊ธฐ ๋๋ฌธ์ boom์ ์ถ๋ ฅํ๊ณ , ์ ๋๋ก ๋ ์ซ์๋ฅผ ํ์ฑ ํ ํ, int๋ก ๋ฐ๊พผ ์๊ฐ 6์ผ๋ก ๋๋์ด ๋จ์ด์ง ๊ฒฝ์ฐ๋ beer๋ฅผ, ๊ทธ๋ ์ง ์์ผ๋ฉด boom์ ์ถ๋ ฅํ๋ค.
๋ฌธ์ ํด๊ฒฐ ๊ณผ์
๋จ์ ๋ ธ๊ฐ๋ค ๊ตฌํ ๋ฌธ์ ์ด๋ค.
0๋ถํฐ 9๊น์ง์ 7 segment ์ซ์ ํ๊ธฐ๋ฒ์ ๋ฏธ๋ฆฌ ์ ์ํ๊ณ ์ฌ๋ฐ๋ฅธ ์๋ฅผ parsing ํด์ผ ํ๋ค.
ํ์ง๋ง ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฒฝ์ฐ์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ํด์ผ ํ๋ค. ์ด๋ ๊ทผ๋ฐ ๋ง์ด ์ด๋ ต์ง ์๋ค.
์ฝ๋๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฒฝ์ฐ์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ๋นผ๋จน์ด ํ๋ฆฌ๋ ์ผ์ด ์๋๋ก ํ์.
'๐ฏ | ๋ฐฑ์ค > ๐ | Silver' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Kotlin, S4] ๋ฐฑ์ค 2358๋ฒ ํํ์ (0) | 2024.09.26 |
---|---|
[Kotlin, S5] ๋ฐฑ์ค 32344๋ฒ ์ ๋ฌผ ๋ฐ๊ตด (0) | 2024.09.23 |
[Kotlin, S2] ๋ฐฑ์ค 18352๋ฒ ํน์ ๊ฑฐ๋ฆฌ์ ๋์ ์ฐพ๊ธฐ (0) | 2024.09.10 |
[Kotlin, S5] ๋ฐฑ์ค 2828๋ฒ ์ฌ๊ณผ ๋ด๊ธฐ ๊ฒ์ (0) | 2024.09.06 |
[Kotlin, S3] ๋ฐฑ์ค 8911๋ฒ ๊ฑฐ๋ถ์ด (0) | 2024.08.30 |