feldblume5263 / TIL

Today I Learned
0 stars 0 forks source link

(221003)[개인 공부] 백준 풀기 #35

Closed feldblume5263 closed 1 year ago

feldblume5263 commented 1 year ago

그냥 체력 되는대로!

feldblume5263 commented 1 year ago

4948

var i = [Int]()
while true {
    let n = Int(readLine()!)!
    if n == 0 { break }
    i.append(n)
}

let max = i.max()! * 2
var res = Array(repeating: true, count: max + 1)
res[0] = false
res[1] = false

for startIdx in 2...max {
    if !res[startIdx] {continue}
    for muliple in stride(from: startIdx * 2, through: max, by: startIdx) {
        res[muliple] = false
    }
}

for n in i {
    var count = 0
    for idx in (n + 1) ... (n + n) {
        if res[idx] { count += 1 }
    }
    print(count)
}

9020

let n = Int(readLine()!)!
var i = [Int]()
for _ in 0..<n {
    let n = Int(readLine()!)!
    i.append(n)
}
let max = i.max()!
var res = Array(repeating: 0, count: max + 1)
for idx in 2...max {
    res[idx] = idx
}
for startIdx in 2...max {
    if res[startIdx] == 0 {continue}
    for muliple in stride(from: startIdx * 2, through: max, by: startIdx) {
        res[muliple] = 0
    }
}
for n in i {
outerLoop: for first in (n / 2) ..< n {
        if res[first] == 0 {continue}
        for second in stride(from: (n / 2) , to: 1, by: -1) {
            if res[second] == 0 {continue}
            if res[first] + res[second] == n {
                print(second, first)
                break outerLoop
            }
        }
    }
}

2750

let n = Int(readLine()!)!
var arr = [Int]()
for _ in 0 ..< n { arr.append(Int(readLine()!)!) }
for n in arr.sorted() { print(n) }

2751

let n = Int(readLine()!)!
var arr = [Int]()
for _ in 0 ..< n { arr.append(Int(readLine()!)!) }
for n in arr.sorted() { print(n) }

2751

let n = Int(readLine()!)!
var arr = [Int]()
for _ in 0 ..< n { arr.append(Int(readLine()!)!) }
for n in arr.sorted() { print(n) }

2751

let n = Int(readLine()!)!
var arr = [Int]()
for _ in 0 ..< n { arr.append(Int(readLine()!)!) }
for n in arr.sorted() { print(n) }

10989

let n = Int(readLine()!)!
var arr = Array(repeating:0,count:10001)
for _ in 0..<n {
    let i = Int(readLine()!)!
    arr[i] += 1
}
var res = ""
for i in 1...10000 {
    res += String(repeating: "\(i)\n",count: arr[i])
}
print(res)

25305

let n = readLine()!.split(separator: " ").map{ Int($0)! }
let inp = readLine()!.split(separator: " ").map{ Int($0)! }
let sor = inp.sorted{$0 > $1}
print(sor[n[1] - 1])