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

[Week2] 김재원 : ATM,가장 큰 수,H-Index,이건 꼭 풀어야 해 #10

Merged
merged 8 commits into from
May 28, 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
16 changes: 16 additions & 0 deletions src/2week/jaewon/ATM.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package `2week`.jaewon

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
var result = 0
var n = readLine().toInt()
val time = readLine().split(" ").map { it.toInt()}.sorted()

time.forEach{
result += it*n
n--
}
print(result)
}
30 changes: 30 additions & 0 deletions src/2week/jaewon/H-Index.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package `2week`.jaewon


class `H-index` {
companion object {
fun getSolution(): Solution {
return Solution()
}
}

class Solution {
fun solution(citations: IntArray): Int {
var answer = 0
citations.sortedDescending().forEachIndexed{ index, num ->
if( index+1 <= num ){ // 인용된 논문의 횟수보다 인용되지 않은 논문의 횟수가 더 많아지는 지점
answer = index+1 // [0]6,[1]5,[2]3,[3]1,[4]0
}
}
return answer
}
}
}


fun main(){
val hIndex = `H-index`.getSolution()
println(hIndex.solution(intArrayOf(10,10,10,10,10)))
println(hIndex.solution(intArrayOf(3,0,6,1,5)))
println(hIndex.solution(intArrayOf(0,0,0,0,0)))
}
1 change: 0 additions & 1 deletion src/2week/jaewon/blank.kt

This file was deleted.

28 changes: 28 additions & 0 deletions src/2week/jaewon/가장 큰 수.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package `2week`.jaewon


class `가장 큰 수` {
companion object {
fun getSolution(): Solution {
return Solution()
}
}

class Solution {
fun solution(numbers: IntArray): String {
var answer = numbers.sortedWith { a, b ->
val aString = a.toString()
val bString = b.toString()
("$bString$aString").compareTo("$aString$bString")
}.joinToString("")


return if(answer[0] == '0') "0" else answer
}
}
}

fun main(){
println(`가장 큰 수`.getSolution().solution(intArrayOf(0,0,0,70)))
}

31 changes: 31 additions & 0 deletions src/2week/jaewon/겹치지 않는 간격.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package `2week`.jaewon

class `겹치지 않는 간격` {
companion object {
fun getSolution(): Solution {
return Solution()
}
}

class Solution {
fun solution(intervals: Array<IntArray>): Int {
intervals.sortBy { it[1] }
var result = 1
var firstTemp = intervals.first()[1]
for(i in 1 until intervals.size){
val (start,end) = intervals[i]
if(firstTemp <= start){
firstTemp = end
result++
}
}
return intervals.size - result
}
}
}

fun main(){
val solution = `겹치지 않는 간격`.getSolution()
println(solution.solution(arrayOf(intArrayOf(1,2), intArrayOf(2,3), intArrayOf(3,4), intArrayOf(1,3))))

}
25 changes: 25 additions & 0 deletions src/2week/jaewon/이건 꼭 풀어야 해.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package `2week`.jaewon

import java.io.*

fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val bw = BufferedWriter(OutputStreamWriter(System.out))
val(n,q) = br.readLine().split(" ").map { it.toInt()}
val numbers = br.readLine().split(" ").map { it.toInt()}.sorted()
val sumList = Array(n+1) { 0 }

numbers.forEachIndexed { index, i ->
sumList[index+1] = sumList[index]+i
}

repeat(q){
val (start,end) = br.readLine().split(" ").map { it.toInt()}
val answer = sumList[end]-sumList[start-1]

bw.write("$answer\n")
}

bw.flush()
bw.close()
}