Advertisement
EvgeniiKraaaaaaaav

SALESMAN(Check test for this prog)

Sep 12th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 4.11 KB | None | 0 0
  1. //https://vk.com/evgenykravchenko0
  2.  
  3.                 ___                                        ___                   ___    
  4.                /  /\                  ___                 /  /\                 /  /\    
  5.               /  /:/_                /__/\               /  /:/_               /  /:/_  
  6.              /  /:/ /\               \  \:\             /  /:/ /\             /  /:/ /\  
  7.             /  /:/ /:/_               \  \:\           /  /:/_/::\           /  /:/ /:/_
  8.            /__/:/ /:/ /\          ___  \__\:\         /__/:/__\/\:\         /__/:/ /:/ /\
  9.            \  \:\/:/ /:/         /__/\ |  |:|         \  \:\ /~~/:/         \  \:\/:/ /:/
  10.             \  \::/ /:/          \  \:\|  |:|          \  \:\  /:/           \  \::/ /:/
  11.              \  \:\/:/            \  \:\__|:|           \  \:\/:/             \  \:\/:/  
  12.               \  \::/              \__\::::/             \  \::/               \  \::/  
  13.                \__\/                   ~~~~               \__\/                 \__\/    
  14.                             ___                                            
  15.                            /__/\                ___                 ___    
  16.                            \  \:\              /  /\               /  /\    
  17.                             \  \:\            /  /:/              /  /:/    
  18.                         _____\__\:\          /__/::\             /__/::\    
  19.                        /__/::::::::\         \__\/\:\__          \__\/\:\__
  20.                        \  \:\~~\~~\/            \  \:\/\            \  \:\/\
  21.                         \  \:\  ~~~              \__\::/             \__\::/
  22.                          \  \:\                  /__/:/              /__/:/
  23.                           \  \:\                 \__\/               \__\/  
  24.                            \__\/                      
  25.  
  26.  
  27. fun travel(adress:String, zipcode:String):String {
  28.    
  29.     var adressCount: Int = 1
  30.     for (comma in adress) {
  31.         if (comma == ',') {
  32.             adressCount++
  33.         }
  34.     }
  35.  
  36.     var arrayAdresses = arrayOfNulls<String>(adressCount)
  37.     var currentAdress: String = ""
  38.     var indexAdress: Int = 0
  39.  
  40.     for (char in adress) {
  41.         if (char == ',') {
  42.             currentAdress = ""
  43.             indexAdress++
  44.         } else {
  45.             currentAdress += char
  46.             arrayAdresses.set(indexAdress, currentAdress)
  47.           }
  48.     }
  49.  
  50.  var arrayHouses = arrayOfNulls<String>(adressCount)
  51.  
  52.     for ((index) in arrayAdresses.withIndex()) {
  53.         arrayHouses[index] = arrayAdresses[index]?.substringBefore(' ')
  54.     }
  55. var arrayZipcodes = arrayOfNulls<String>(adressCount)
  56.     var zipcodeLength: Int
  57.  
  58.     for ((index) in arrayAdresses.withIndex()) {
  59.         zipcodeLength = arrayAdresses[index]?.length!!.minus(8)
  60.         arrayZipcodes[index] = arrayAdresses[index]?.drop(zipcodeLength)
  61.     }
  62.  
  63.     var countSuitable: Int = 0
  64.  
  65.     for (code in arrayZipcodes) {
  66.         if (code == zipcode) {
  67.             countSuitable++
  68.         }
  69.     }
  70.     if (countSuitable != 0) {
  71.  
  72.         var suitableZip          = arrayOfNulls<Int>(countSuitable)
  73.         var curentIndex: Int     = 0
  74.         var resultStreet: String = ""
  75.  
  76.         for ((index) in arrayZipcodes.withIndex()) {
  77.             if (arrayZipcodes[index] == zipcode) {
  78.                 resultStreet += arrayAdresses[index].toString().dropLast(9).substringAfter(' ') + ','
  79.                 suitableZip[curentIndex] = index
  80.                 curentIndex++
  81.             }
  82.         }
  83.         curentIndex--
  84.  
  85.         var resultHouses: String = ""
  86.  
  87.         for ((indexH) in arrayHouses.withIndex()) {
  88.             for ((indexZ) in suitableZip.withIndex()) {
  89.                 if (suitableZip[indexZ] == indexH) {
  90.                         resultHouses += arrayHouses[indexH] + ","
  91.                 }
  92.             }
  93.         }
  94.          resultStreet = resultStreet.substringBeforeLast(',')
  95.          var resultString: String = (zipcode + ':' + resultStreet + '/' + resultHouses).substringBeforeLast(',')
  96.          return resultString
  97.     }
  98.     else {
  99.         var resultz: String = zipcode + ":/"
  100.         return resultz
  101.     }
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement