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, 잃어버린 괄호, 큰 수 만들기 #28

Merged
merged 5 commits into from
Jun 26, 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
18 changes: 18 additions & 0 deletions src/6week/jaewon/동전.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package `6week`.jaewon

fun main(){
var(n,k) = readln().split(" ").map {it.toInt()}
val coinList = mutableListOf<Int>()
var answer = 0

repeat(n){
coinList.add(readln().toInt())
}

coinList.reversed().forEach {
if(k == 0 ){ return@forEach }
answer += k/it
k %= it
}
print(answer)
}
16 changes: 16 additions & 0 deletions src/6week/jaewon/수리공 항승.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package `6week`.jaewon

fun main(){
val (_,l) = readln().split(" ").map{it.toInt()}
val location = readln().split(" ").map{it.toInt()}.sorted()
var current = 0;
var cnt = 0;

location.forEach {
if(it+0.5 > current){
cnt++
current = it+l
}
}
print(cnt)
}
21 changes: 21 additions & 0 deletions src/6week/jaewon/신입 사원.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package `6week`.jaewon

fun main(){
val t = readln().toInt()
repeat(t){
val n = readln().toInt()
val result = mutableListOf<Pair<Int,Int>>()
var answer = 0
repeat(n){
val (a,b) = readln().split(" ").map{it.toInt()}
result.add(Pair(a,b))
}
Comment on lines +9 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수 따로 안만들고 Array로 뺐으면 바로 배열로 만들어 쓸 수 있었을거같아요


result.forEach { oneResult ->
if(result.filter{ it.first < oneResult.first }.none{it.second < oneResult.second}){
answer++
}
}
print(answer)
}
}
8 changes: 8 additions & 0 deletions src/6week/jaewon/잃어버린 괄호.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package `6week`.jaewon

fun main(){
print(readln()
.split("-")
.map{it.split("+").map { it.toInt() }.reduce { acc, s -> acc+s }}
.reduce{total,num -> total-num})
Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 reduce 장인....

}
37 changes: 37 additions & 0 deletions src/6week/jaewon/큰 수 만들기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package `6week`.jaewon

import java.util.Stack

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

class Solution{
fun solution(number: String, k: Int): String {
var answer = ""
var start = 0
while (start < number.length && answer.length != number.length-k){
val front = k + answer.length +1
var max = 0
for(i in start until front){
if(max < number[i].digitToInt()){
max = number[i].digitToInt()
start = i +1
}
}
answer = "${answer}${max}"
}
return answer
}
}
}

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