SWIFT学習Baek Junアルゴリズム1546平均値

576 ワード

let a = Int(readLine()!)!
let b = readLine()!.split(separator:" ").map{Float(String($0))!}
var c : Float = 0

for i in 1...a {
  c += (b[i-1] / b.max()! * 100)
}

print(c/Float(a))
//////////////////////
let a = Int(readLine()!)!
let b = readLine()!.split(separator:" ").map{Float(String($0))!}
var c : [Float] = []

for i in 1...a {
  c.append(b[i-1] / b.max()! * 100)
}

let x = c.reduce(0) { (a: Float, b: Float) -> Float in
    return a + b
}

print(x/Float(a))