Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Week6] 박서윤: 수리공 항승, 동전 0, 신입사원, 큰 수 만들기, 잃어버린 괄호 #31

Merged
merged 5 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/6week/seoyoon/동전 0.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package `6week`.seoyoon

fun main() {
var (N, K) = readln().split(" ").map{ it.toInt() }
val coin = IntArray(N) { readln().toInt() }
var cnt = 0

for (i in N - 1 downTo 0) {
cnt += K / coin[i]
K = K % coin[i]
}
println(cnt)
}
18 changes: 18 additions & 0 deletions src/6week/seoyoon/수리공 항승.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package `6week`.seoyoon

fun main() {
val (N, L) = readln().split(" ").map{ it.toInt() }
val water = readln().split(" ").map{ it.toInt() }.toIntArray()
var cnt = 1

water.sort()
var tape = water[0] + L - 0.5

for (i in 1 until N) {
if (tape < water[i]) {
cnt++
tape = water[i] + L - 0.5
}
}
println(cnt)
}
24 changes: 24 additions & 0 deletions src/6week/seoyoon/신입 사원.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package `6week`.seoyoon

fun main() {
val T = readln().toInt()
repeat(T) {
val N = readln().toInt()
val rank = Array(N, { IntArray(2) })
var cnt = 1

repeat(N) {
rank[it] = readln().split(" ").map{ it.toInt() }.toIntArray()
}
var sorted = rank.sortedBy{ it.first() }

var compare = sorted[0][1]
repeat(N) {
if (sorted[it][1] < compare) {
cnt++
compare = sorted[it][1]
}
}
println(cnt)
}
}
14 changes: 14 additions & 0 deletions src/6week/seoyoon/잃어버린 괄호.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package `6week`.seoyoon

fun main() {
var answer = 0
val str = readln().split("-").toMutableList()
repeat(str.size) {
if (str[it].contains("+")) {
var midSum = str[it].split("+").map{ it.toInt() }.reduce{total, sum -> total + sum}
str[it] = midSum.toString()
}
}
answer = str.map{ it.toInt() }.reduce{ total, sum -> total - sum }
println(answer)
}
38 changes: 38 additions & 0 deletions src/6week/seoyoon/큰 수 만들기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package `6week`.seoyoon

class `큰 수 만들기` {
companion object {
fun getSolution(): Solution {
return Solution()
}
}

class Solution {
fun solution(number: String, k: Int): String {
var answer = StringBuilder()
var idx = 0

for (i in 0 until number.length) {
if (answer.length == number.length - k) {
return answer.toString()
}
var max = 0
for (j in idx .. k + i) {
if (number[j].digitToInt() > max) {
max = number[j].digitToInt()
idx = j + 1
}
}
answer.append(max)
}
return answer.toString()
}
}
}

fun main() {
val solution = `큰 수 만들기`.getSolution()
println(solution.solution("1924", 2))
println(solution.solution("1231234", 3))
println(solution.solution("4177252841", 4))
}