Skip to content
Open
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: 11 additions & 2 deletions src/main/kotlin/subtask1/HappyArray.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ package subtask1

class HappyArray {

// TODO: Complete the following function
fun convertToHappy(sadArray: IntArray): IntArray {
throw NotImplementedError("Not implemented")
var i = 1
var happyList = sadArray.toMutableList()
while (i < happyList.size - 1) {
if ( i != 0 && happyList[i] > happyList[i + 1] + happyList[i - 1]) {
happyList.removeAt(i)
i --
} else {
i ++
}
}
return happyList.toIntArray()
}
}
9 changes: 6 additions & 3 deletions src/main/kotlin/subtask2/BillCounter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package subtask2

class BillCounter {

// TODO: Complete the following function
// The output could be "Bon Appetit" or the string with number(e.g "10")
fun calculateFairlySplit(bill: IntArray, k: Int, b: Int): String {
throw NotImplementedError("Not implemented")
val sum = (bill.sum() - bill[k]) / 2
return if (sum - b == 0) {
"Bon Appetit"
} else {
(b - sum).toString()
}
}
}
24 changes: 22 additions & 2 deletions src/main/kotlin/subtask3/StringParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ package subtask3

class StringParser {

// TODO: Complete the following function
fun getResult(inputString: String): Array<String> {
throw NotImplementedError("Not implemented")
val result: MutableList<String> = mutableListOf()
inputString.forEachIndexed { index, s ->
when (s) {
'(' -> result.add(getSubString(inputString, index, '(', ')'))
'[' -> result.add(getSubString(inputString, index, '[', ']'))
'<' -> result.add(getSubString(inputString, index, '<', '>'))
}
}
return result.toTypedArray()
}

private fun getSubString(inputString: String, index: Int, openingChar: Char, closingChar: Char): String {
var i = index
var n = 0
while (n < 1) {
i++
if (inputString[i] == openingChar)
n--
if (inputString[i] == closingChar)
n++
}
return (inputString.substring(index + 1, i))
}
}