Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://vk.com/evgenykravchenko0
- ___ ___ ___
- / /\ ___ / /\ / /\
- / /:/_ /__/\ / /:/_ / /:/_
- / /:/ /\ \ \:\ / /:/ /\ / /:/ /\
- / /:/ /:/_ \ \:\ / /:/_/::\ / /:/ /:/_
- /__/:/ /:/ /\ ___ \__\:\ /__/:/__\/\:\ /__/:/ /:/ /\
- \ \:\/:/ /:/ /__/\ | |:| \ \:\ /~~/:/ \ \:\/:/ /:/
- \ \::/ /:/ \ \:\| |:| \ \:\ /:/ \ \::/ /:/
- \ \:\/:/ \ \:\__|:| \ \:\/:/ \ \:\/:/
- \ \::/ \__\::::/ \ \::/ \ \::/
- \__\/ ~~~~ \__\/ \__\/
- ___
- /__/\ ___ ___
- \ \:\ / /\ / /\
- \ \:\ / /:/ / /:/
- _____\__\:\ /__/::\ /__/::\
- /__/::::::::\ \__\/\:\__ \__\/\:\__
- \ \:\~~\~~\/ \ \:\/\ \ \:\/\
- \ \:\ ~~~ \__\::/ \__\::/
- \ \:\ /__/:/ /__/:/
- \ \:\ \__\/ \__\/
- \__\/
- fun travel(adress:String, zipcode:String):String {
- var adressCount: Int = 1
- for (comma in adress) {
- if (comma == ',') {
- adressCount++
- }
- }
- var arrayAdresses = arrayOfNulls<String>(adressCount)
- var currentAdress: String = ""
- var indexAdress: Int = 0
- for (char in adress) {
- if (char == ',') {
- currentAdress = ""
- indexAdress++
- } else {
- currentAdress += char
- arrayAdresses.set(indexAdress, currentAdress)
- }
- }
- var arrayHouses = arrayOfNulls<String>(adressCount)
- for ((index) in arrayAdresses.withIndex()) {
- arrayHouses[index] = arrayAdresses[index]?.substringBefore(' ')
- }
- var arrayZipcodes = arrayOfNulls<String>(adressCount)
- var zipcodeLength: Int
- for ((index) in arrayAdresses.withIndex()) {
- zipcodeLength = arrayAdresses[index]?.length!!.minus(8)
- arrayZipcodes[index] = arrayAdresses[index]?.drop(zipcodeLength)
- }
- var countSuitable: Int = 0
- for (code in arrayZipcodes) {
- if (code == zipcode) {
- countSuitable++
- }
- }
- if (countSuitable != 0) {
- var suitableZip = arrayOfNulls<Int>(countSuitable)
- var curentIndex: Int = 0
- var resultStreet: String = ""
- for ((index) in arrayZipcodes.withIndex()) {
- if (arrayZipcodes[index] == zipcode) {
- resultStreet += arrayAdresses[index].toString().dropLast(9).substringAfter(' ') + ','
- suitableZip[curentIndex] = index
- curentIndex++
- }
- }
- curentIndex--
- var resultHouses: String = ""
- for ((indexH) in arrayHouses.withIndex()) {
- for ((indexZ) in suitableZip.withIndex()) {
- if (suitableZip[indexZ] == indexH) {
- resultHouses += arrayHouses[indexH] + ","
- }
- }
- }
- resultStreet = resultStreet.substringBeforeLast(',')
- var resultString: String = (zipcode + ':' + resultStreet + '/' + resultHouses).substringBeforeLast(',')
- return resultString
- }
- else {
- var resultz: String = zipcode + ":/"
- return resultz
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement