Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package preexam
- import java.io.File
- import java.io.IOException
- fun foo(inputName: String, query: String): Any {
- var result = mutableListOf<String>()
- val request = query.split(" ")
- if (request.size != 2)
- throw IllegalArgumentException()
- val code = request[0]
- val amount = request[1]
- var map = mutableMapOf<String, List<String>>()
- val file = File(inputName)
- if (file == null) {
- throw IOException()
- }
- for (str in file.readLines()) {
- var key = str.split(": ")[0]
- var value = str.split(": ")[1].split(", ", " ")
- if (value.size != 5)
- throw IllegalArgumentException()
- map.put(key, value)
- }
- var sb = StringBuilder()
- if (code == "*") {
- for ((key, value) in map) {
- if (value[1].toInt() >= amount.toInt())
- sb.append(value[0]).append(", достаточно, общая стоимость ")
- .append((value[1].toInt()) * (value[3].toInt())).append(" р,\n")
- }
- } else {
- for ((key, value) in map) {
- if (code == key) {
- if (value[1].toInt() >= amount.toInt())
- sb.append(value[0]).append(", достаточно, общая стоимость ")
- .append(value[1].toInt() * value[3].toInt()).append(" р,\b")
- else
- sb.append(value[0]).append(", недостаточно, общая стоимость ")
- .append(value[1].toInt() * value[3].toInt()).append(" р,\b")
- }
- }
- }
- return sb.toString().dropLast(2)
- }
Advertisement
Add Comment
Please, Sign In to add comment