Advertisement
NarekNavoyan

Untitled

Aug 25th, 2023
1,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.35 KB | None | 0 0
  1. package edu.example
  2.  
  3. fun main() {
  4.     val bills = arrayOf(500, 200, 100, 50, 20, 10)
  5.  
  6.     var count = 0
  7.     var sum = readln().toInt()
  8.  
  9.     var currentBillIndex = 0
  10.     while (sum >= 10) {
  11.         if (sum >= bills[currentBillIndex]) {
  12.             sum -= bills[currentBillIndex];
  13.             count++
  14.         }
  15.         else {
  16.             currentBillIndex++;
  17.         }
  18.     }
  19.  
  20.     println(if (sum == 0) count else -1)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement