-
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.
solve: π κΈ°μ μ λ§€λ§€λ² π
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/heejik/13week/π κΈ°μ μ λ§€λ§€λ² π.kt
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,71 @@ | ||
package heejik.`13week` | ||
|
||
class `π κΈ°μ μ λ§€λ§€λ² π` { | ||
|
||
fun solve() { | ||
val money = readln().toInt() | ||
val stocks = readln().split(' ').map { it.toInt() } | ||
|
||
val bnf = bnf(money, stocks) | ||
val timing = timing(money, stocks) | ||
|
||
println( | ||
if (bnf > timing) "BNP" | ||
else if (timing > bnf) "TIMING" | ||
else "SAMESAME" | ||
) | ||
} | ||
|
||
private fun bnf(_money: Int, stocks: List<Int>): Int { | ||
var money = _money | ||
var stock = 0 | ||
|
||
stocks.forEach { | ||
val cnt = money / it | ||
money -= it * (cnt) | ||
stock += cnt | ||
} | ||
|
||
return money + (stock * stocks.last()) | ||
} | ||
|
||
private fun timing(_money: Int, stocks: List<Int>): Int { | ||
var money = _money | ||
var stock = 0 | ||
|
||
var upCnt = 0 | ||
var downCnt = 0 | ||
var preStock = stocks.first() | ||
|
||
stocks.drop(0).forEach { | ||
if (it > preStock) { | ||
upCnt++ | ||
downCnt = 0 | ||
} else if (it < preStock) { | ||
downCnt++ | ||
upCnt = 0 | ||
} else { | ||
upCnt = 0 | ||
downCnt = 0 | ||
} | ||
|
||
if (upCnt >= 3) { | ||
money += stock * it | ||
stock = 0 | ||
} | ||
if (downCnt >= 3) { | ||
val cnt = money / it | ||
money -= it * (cnt) | ||
stock += cnt | ||
} | ||
|
||
preStock = it | ||
} | ||
|
||
return money + (stock * stocks.last()) | ||
} | ||
} | ||
|
||
fun main() { | ||
`π κΈ°μ μ λ§€λ§€λ² π`().solve() | ||
} |