Guest User

Untitled

a guest
Jan 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.66 KB | None | 0 0
  1. package preexam
  2.  
  3. import java.io.File
  4. import java.io.IOException
  5.  
  6.  
  7. fun foo(inputName: String, query: String): Any {
  8.     var result = mutableListOf<String>()
  9.     val request = query.split(" ")
  10.     if (request.size != 2)
  11.         throw IllegalArgumentException()
  12.     val code = request[0]
  13.     val amount = request[1]
  14.     var map = mutableMapOf<String, List<String>>()
  15.     val file = File(inputName)
  16.     if (file == null) {
  17.         throw IOException()
  18.     }
  19.     for (str in file.readLines()) {
  20.         var key = str.split(": ")[0]
  21.         var value = str.split(": ")[1].split(", ", " ")
  22.         if (value.size != 5)
  23.             throw IllegalArgumentException()
  24.         map.put(key, value)
  25.     }
  26.     var sb = StringBuilder()
  27.     if (code == "*") {
  28.         for ((key, value) in map) {
  29.             if (value[1].toInt() >= amount.toInt())
  30.                 sb.append(value[0]).append(", достаточно, общая стоимость ")
  31.                         .append((value[1].toInt()) * (value[3].toInt())).append(" р,\n")
  32.         }
  33.     } else {
  34.         for ((key, value) in map) {
  35.             if (code == key) {
  36.                 if (value[1].toInt() >= amount.toInt())
  37.                     sb.append(value[0]).append(", достаточно, общая стоимость ")
  38.                             .append(value[1].toInt() * value[3].toInt()).append(" р,\b")
  39.                 else
  40.                     sb.append(value[0]).append(", недостаточно, общая стоимость ")
  41.                             .append(value[1].toInt() * value[3].toInt()).append(" р,\b")
  42.             }
  43.         }
  44.     }
  45.     return sb.toString().dropLast(2)
  46. }
Advertisement
Add Comment
Please, Sign In to add comment