Skip to content

Commit

Permalink
Решил countSubstrings из 8 урока Kotlin-Polytech#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya1998 committed Jan 29, 2017
1 parent 3d8112f commit 0e1428d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lesson8/task1/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ fun alignFile(inputName: String, lineLength: Int, outputName: String) {
*
*/
fun countSubstrings(inputName: String, substrings: List<String>): Map<String, Int> {
TODO()
val text = File(inputName).readText().toLowerCase()
val substrs = mutableMapOf<String, Int>()
for (substring in substrings) {
val count = (text.length - text.replace(substring.toLowerCase(), "").length) / substring.length
substrs.put(substring, count)
}
return substrs
}


Expand All @@ -64,6 +70,7 @@ fun countSubstrings(inputName: String, substrings: List<String>): Map<String, In




/**
* Средняя
*
Expand Down Expand Up @@ -105,6 +112,7 @@ fun centerFile(inputName: String, outputName: String) {




/**
* Сложная
*
Expand Down

0 comments on commit 0e1428d

Please sign in to comment.