Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let daysInTheMouths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- let mouths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
- //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)]
- var mouthsAndDays = [(mouths : String, days : Int)](repeating: ("" , 0), count: 12)
- var mouthsAndDays1 = [(mouths : String, days : Int)]()
- for i in daysInTheMouths {
- print(i)
- }
- for i in 0..<daysInTheMouths.count {
- print(mouths[i] + " : " + String(daysInTheMouths[i]))
- }
- print("\n")
- for (index, value) in daysInTheMouths.enumerated() {
- print("\(mouths[index]) : \(value)")
- }
- print("\n")
- for i in 0..<daysInTheMouths.count {
- mouthsAndDays[i].mouths = mouths[i]
- mouthsAndDays[i].days = daysInTheMouths[i]
- }
- for i in 0..<daysInTheMouths.count {
- let mouth = (mouths[i], daysInTheMouths[i])
- mouthsAndDays1.append(mouth)
- }
- for i in 0..<daysInTheMouths.count {
- print(mouthsAndDays[i])
- }
- print("\n")
- for i in 0..<daysInTheMouths.count {
- print(mouthsAndDays1[i])
- }
- print("\n")
- for i in stride(from: daysInTheMouths.count-1, to: -1, by: -1) {
- print(mouths[i] + " : " + String(daysInTheMouths[i]))
- }
- print("\n")
- let dob = (moth: 7, day: 19)
- var sum = Int()
- for i in 0...dob.moth-1 {
- if i == dob.moth-1 {
- sum += dob.day
- } else {
- sum += mouthsAndDays[i].days
- }
- }
- print("Days before my birthday : \(sum)\n")
- //2 задание
- let consts = [Int("34"), Int("45h"), Int("4h4"), Int("59"), Int("35j")]
- var sumOfConsts1 = Int()
- var sumOfConsts2 = Int()
- var sumOfConsts3 = Int()
- for i in consts {
- if let tmp = i {
- sumOfConsts1 += tmp
- }
- }
- for i in consts {
- if i != nil {
- sumOfConsts2 += i!
- }
- }
- for i in consts {
- sumOfConsts3 += i ?? 0
- }
- print(sumOfConsts1)
- print(sumOfConsts2)
- print(sumOfConsts3)
- print("\n")
- //3 задание
- let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- var reverseAlphabet = Array(repeating: "", count: alphabet.count)
- var i = 0
- for letter in alphabet {
- reverseAlphabet[(alphabet.count-1)-i] += String(letter)
- i += 1
- }
- var reverseAlphabet1 = [String]()
- for letter in alphabet {
- reverseAlphabet1.insert(String(letter), at: 0)
- }
- for j in reverseAlphabet {
- if j == "A" {
- print(j)
- break
- }
- print(j, terminator: " , ")
- }
- for i in reverseAlphabet1 {
- if i == "A" {
- print(i)
- break
- }
- print(i, terminator: " , ")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement