Advertisement
patek968

Erőpróba - Kígyó

Jan 10th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.87 KB | None | 0 0
  1. //
  2. //  main.swift
  3. //  kigyo
  4. //
  5.  
  6. import Foundation
  7. let sor = 4
  8. let oszlop = 5
  9. var tomb  = [[Int]]()
  10. for _ in 1...sor
  11. {
  12.     var beszurando = [Int]()
  13.     for _ in 1...oszlop
  14.     {
  15.         beszurando.append(Int.random(in: 0...9))
  16.     }
  17.     tomb.append(beszurando)
  18. }
  19. for i in 0...sor-1
  20. {
  21.     print(tomb[i])
  22. }
  23. print()
  24. var fel_le = false
  25. // fel: true
  26. // le: false
  27. var melyikoszlop = 0
  28. var kimenet = [Int]()
  29. while melyikoszlop < oszlop
  30. {
  31.     if !fel_le
  32.     {
  33.         for i in 0...sor-1
  34.         {
  35.             kimenet.append(tomb[i][melyikoszlop])
  36.         }
  37.         melyikoszlop += 1
  38.         fel_le = true
  39.         continue
  40.     }
  41.     else if fel_le
  42.     {
  43.         for i in 0...sor-1
  44.         {
  45.             kimenet.append(tomb[sor-1-i][melyikoszlop])
  46.         }
  47.         melyikoszlop += 1
  48.         fel_le = false
  49.         continue
  50.     }
  51. }
  52. print (kimenet)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement