Advertisement
vadim_sharaf

Untitled

Mar 7th, 2023 (edited)
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.60 KB | None | 0 0
  1. let daysInTheMouths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  2. let mouths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
  3. //var mouthsAndDays: [(mouths: String, days: Int)] = [("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1), ("f", 1)]
  4. var mouthsAndDays = [(mouths : String, days : Int)](repeating: ("" , 0), count: 12)
  5. var mouthsAndDays1 = [(mouths : String, days : Int)]()
  6. for i in daysInTheMouths {
  7.     print(i)
  8. }
  9. for i in 0..<daysInTheMouths.count {
  10.     print(mouths[i] + " : " + String(daysInTheMouths[i]))
  11. }
  12. print("\n")
  13. for (index, value) in daysInTheMouths.enumerated() {
  14.     print("\(mouths[index]) : \(value)")
  15. }
  16. print("\n")
  17. for i in 0..<daysInTheMouths.count {
  18.     mouthsAndDays[i].mouths = mouths[i]
  19.     mouthsAndDays[i].days = daysInTheMouths[i]
  20. }
  21. for i in 0..<daysInTheMouths.count {
  22.     let mouth = (mouths[i], daysInTheMouths[i])
  23.     mouthsAndDays1.append(mouth)
  24. }
  25. for i in 0..<daysInTheMouths.count {
  26.     print(mouthsAndDays[i])
  27. }
  28. print("\n")
  29. for i in 0..<daysInTheMouths.count {
  30.     print(mouthsAndDays1[i])
  31. }
  32. print("\n")
  33. for i in stride(from: daysInTheMouths.count-1, to: -1, by: -1) {
  34.     print(mouths[i] + " : " + String(daysInTheMouths[i]))
  35. }
  36. print("\n")
  37. let dob = (moth: 7, day: 19)
  38. var sum = Int()
  39. for i in 0...dob.moth-1 {
  40.     if i == dob.moth-1 {
  41.         sum += dob.day
  42.     } else {
  43.         sum += mouthsAndDays[i].days
  44.     }
  45. }
  46. print("Days before my birthday : \(sum)\n")
  47.  
  48. //2 задание
  49. let consts = [Int("34"), Int("45h"), Int("4h4"), Int("59"), Int("35j")]
  50. var sumOfConsts1 = Int()
  51. var sumOfConsts2 = Int()
  52. var sumOfConsts3 = Int()
  53. for i in consts {
  54.     if let tmp = i {
  55.         sumOfConsts1 += tmp
  56.     }
  57. }
  58. for i in consts {
  59.     if i != nil {
  60.         sumOfConsts2 += i!
  61.     }
  62. }
  63. for i in consts {
  64.     sumOfConsts3 += i ?? 0
  65. }
  66. print(sumOfConsts1)
  67. print(sumOfConsts2)
  68. print(sumOfConsts3)
  69. print("\n")
  70.  
  71. //3 задание
  72. let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  73. var reverseAlphabet = Array(repeating: "", count: alphabet.count)
  74. var i = 0
  75. for letter in alphabet {
  76.     reverseAlphabet[(alphabet.count-1)-i] += String(letter)
  77.     i += 1
  78. }
  79. var reverseAlphabet1 = [String]()
  80. for letter in alphabet {
  81.     reverseAlphabet1.insert(String(letter), at: 0)
  82. }
  83. for j in reverseAlphabet {
  84.     if j == "A" {
  85.         print(j)
  86.         break
  87.     }
  88.     print(j, terminator: " , ")
  89. }
  90. for i in reverseAlphabet1 {
  91.     if i == "A" {
  92.         print(i)
  93.         break
  94.     }
  95.     print(i, terminator: " , ")
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement