feldblume5263 / TIL

Today I Learned
0 stars 0 forks source link

(220822)[개인 공부] 백준 (1시간) #11

Closed feldblume5263 closed 2 years ago

feldblume5263 commented 2 years ago

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

feldblume5263 commented 2 years ago

11021

let c = Int(readLine()!)!
var n: [[Int]] = []
for _ in 0..<c {
    n.append(readLine()!.split(separator: " ").map { Int($0)! })
}
for idx in 0..<c {
    print("Case #\(idx + 1): \(n[idx][0] + n[idx][1])")
}

11022

let c = Int(readLine()!)!
var n: [[Int]] = []
for _ in 0..<c {
    n.append(readLine()!.split(separator: " ").map { Int($0)! })
}
for idx in 0..<c {
    print("Case #\(idx + 1): \(n[idx][0]) + \(n[idx][1]) = \(n[idx][0] + n[idx][1])")
}

2438

let n = Int(readLine()!)!

for idx in 0..<n {
    for _ in 1...idx + 1 {
        print("*", terminator: "")
    }
    print("")
}

2439

let n = Int(readLine()!)!

for idx in 1...n {
    for _ in 0..<(n - idx) {
        print(" ", terminator: "")
    }
    for _ in 1...idx {
        print("*", terminator: "")
    }
    print("")
}

10871

let nx = readLine()!.split(separator: " ").map { Int($0)! }
let input = readLine()!.split(separator: " ").map { Int($0)! }
var num: [Int] = []
for idx in 0..<nx[0] {
    if input[idx] < nx[1] {
        print(input[idx], terminator: " ")
    }
}

10951

while let line = readLine() {
    let input = line.split(separator: " ").map { Int($0)! }
    print(input[0] + input[1])
}

1110

let n = Int(readLine()!)!
var k = n
var count = 0
while k != n || count == 0 {
    count += 1
    k = (k % 10) * 10 + (((k / 10) + (k % 10)) % 10)
}
print(count)