baekjoon 20251228
This commit is contained in:
parent
8057e3788c
commit
4a77cd5636
1
code_study/Baekjoon/python/5565.py
Normal file
1
code_study/Baekjoon/python/5565.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(int(input()) - sum([int(input()) for _ in range(9)]))
|
||||||
41
code_study/Baekjoon/swift/17103.swift
Normal file
41
code_study/Baekjoon/swift/17103.swift
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
let MAX_NUM: Int = 1000000
|
||||||
|
let SQRT_MAX = Int(sqrt(Double(MAX_NUM)))
|
||||||
|
|
||||||
|
var isPrime: [Bool] = Array(repeating: true, count: MAX_NUM+1)
|
||||||
|
(isPrime[0], isPrime[1]) = (false, false)
|
||||||
|
|
||||||
|
for n in 2...SQRT_MAX {
|
||||||
|
if isPrime[n] {
|
||||||
|
for i in stride(from: n*n, through: MAX_NUM, by: n) {
|
||||||
|
isPrime[i] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pairCount(_ num: Int) -> Int {
|
||||||
|
var ans: Int = 0
|
||||||
|
|
||||||
|
for n in 2...num/2 {
|
||||||
|
if isPrime[n] && isPrime[num-n] {
|
||||||
|
ans += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ans
|
||||||
|
}
|
||||||
|
|
||||||
|
func solve() -> [String] {
|
||||||
|
var result: [String] = []
|
||||||
|
guard let T = Int(readLine() ?? "") else { return []}
|
||||||
|
|
||||||
|
for _ in 0..<T {
|
||||||
|
guard let N = Int(readLine() ?? "") else { break }
|
||||||
|
result.append(String(pairCount(N)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
print(solve().joined(separator: "\n"))
|
||||||
51
code_study/Baekjoon/swift/2623.swift
Normal file
51
code_study/Baekjoon/swift/2623.swift
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
func solve() {
|
||||||
|
guard let input1 = readLine() else { return }
|
||||||
|
var NM = input1.split(separator : " ").compactMap{Int($0)}
|
||||||
|
let (N, M) = (NM[0], NM[1])
|
||||||
|
|
||||||
|
var graph: [[Int]] = Array(repeating: [], count: N+1)
|
||||||
|
var indegree: [Int] = Array(repeating: 0, count: N+1)
|
||||||
|
|
||||||
|
for _ in 1...M {
|
||||||
|
guard let input2 = readLine() else { break }
|
||||||
|
let seq: [Int] = input2.split(separator: " ").compactMap{Int($0)}
|
||||||
|
|
||||||
|
for i in 1..<seq[0] {
|
||||||
|
let (u, v) = (seq[i], seq[i+1])
|
||||||
|
graph[u].append(v)
|
||||||
|
indegree[v] += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var qu: [Int] = []
|
||||||
|
var idx: Int = 0
|
||||||
|
var result: [String] = []
|
||||||
|
|
||||||
|
for i in 1...N {
|
||||||
|
if indegree[i] == 0 {
|
||||||
|
qu.append(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while idx < qu.count {
|
||||||
|
let now: Int = qu[idx]
|
||||||
|
idx += 1
|
||||||
|
result.append(String(now))
|
||||||
|
|
||||||
|
for nxt in graph[now] {
|
||||||
|
indegree[nxt] -= 1
|
||||||
|
if indegree[nxt] == 0 {
|
||||||
|
qu.append(nxt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.count != N {
|
||||||
|
print(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print(result.joined(separator: "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
solve()
|
||||||
Loading…
x
Reference in New Issue
Block a user