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
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/main/kotlin/subtask1/HappyArray.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ package subtask1

class HappyArray {

// TODO: Complete the following function
fun convertToHappy(sadArray: IntArray): IntArray {
throw NotImplementedError("Not implemented")

val resultList = mutableListOf<Int>()

if (sadArray.isNotEmpty()) {
resultList.add(sadArray[0])
for (i in 1 until sadArray.lastIndex) {
when {
(sadArray[i] <= resultList.last() + sadArray[i + 1]) -> resultList.add(sadArray[i])
else -> {
for (j in resultList.lastIndex downTo 1) {
if (resultList[j] > resultList[j - 1] + sadArray[i + 1]) resultList.removeAt(j)
}
}
}
}
resultList.add(sadArray.last())
}
return resultList.toIntArray()
}
}

10 changes: 6 additions & 4 deletions src/main/kotlin/subtask2/BillCounter.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,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")
var result = "StringResult"
var billAnna = (bill.filter { i -> i != bill[k] }.sum()) / 2

if (billAnna == b) result = "Bon Appetit"
else result = (b - billAnna).toString()
return result
}
}
48 changes: 46 additions & 2 deletions src/main/kotlin/subtask3/StringParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,52 @@ package subtask3

class StringParser {

// TODO: Complete the following function
fun getResult(inputString: String): Array<String> {
throw NotImplementedError("Not implemented")
val target = listOf<Char>('(', ')', '<', '>', '[', ']')
val result = mutableListOf<String>()
var count = 0
var min = 0
val max = inputString.length - 1

for (i in 0..max) {
if (target.contains(inputString[i])) {
when (inputString[i]) {
'(' -> {
if (i < max) min = i + 1
count = 0
for (j in min..max) {
when(inputString[j]) {
')' -> if ( count == 0 ) result.add(inputString.substring(min, j))
else count--
'(' -> count++
}
}
}
'[' -> {
if (i < max) min = i + 1
count = 0
for (j in min..max) {
when(inputString[j]) {
']' -> if ( count == 0) result.add(inputString.substring(min, j))
else count--
'[' -> count++
}
}
}
'<' -> {
if (i < max) min = i + 1
count = 0
for (j in min..max) {
when(inputString[j]) {
'>' -> if ( count == 0) result.add(inputString.substring(min, j))
else count--
'<' -> count++
}
}
}
}
}
}
return result.toTypedArray()
}
}