feldblume5263 / TIL

Today I Learned
0 stars 0 forks source link

(220826)[개인 공부] 백준 (1시간) #15

Closed feldblume5263 closed 2 years ago

feldblume5263 commented 2 years ago

1시간 동안 문제 풀기 재미보다는 가독성과 시간복잡도를 더 신경쓰자.

feldblume5263 commented 2 years ago

3003

var n = readLine()!.split(separator: " ").map { Int($0)! }
for i in 0 ..< n.count {
    if i <= 1 {
        n[i] = 1 - n[i]
    } else if i < 5 {
        n[i] = 2 - n[i]
    } else {
        n[i] = 8 - n[i]
    }
    print(n[i], terminator: " ")
}

10818 min 함수와 max 함수를 쓰면 더 간단할 것 같다!

Int(readLine()!)!
let ns = readLine()!.split(separator: " ").map{ Int($0)!}
var l = ns[0]
var s = ns[0]
for n in ns {
    if n > l { l = n }
    if n < s { s = n }
}
print("\(s) \(l)")

2562

var l = 0
var li = 0
for i in 1...9 {
    let inp = Int(readLine()!)!
    if l < inp {
        l = inp
        li = i
    }
}
print("\(l)\n\(li)")

3052

var a = [Int]()
for _ in 0..<10 {
    let n = Int(readLine()!)! % 42
    if a.firstIndex(of: n) == nil {
        a.append(n)
    }
}
print(a.count)

1546

let c = Double(readLine()!)!
let n = readLine()!.split(separator: " ").map{ Double($0)! }
let h = n.max()!
print(n.map{ $0 / h * 100}.reduce(0, +) / c)