-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10989번.swift
69 lines (53 loc) · 1.57 KB
/
10989번.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 출처 : 백준 수 정렬하기 3
// https://www.acmicpc.net/problem/10989
// 풀이 : hogumachu
// 입출력의 크기를 잘 확인하자
import Foundation
let file = FileIO()
let n = file.readInt()
var values: [Int] = Array(repeating: 0, count: 10_001)
var result = ""
for _ in 0..<n {
values[file.readInt()] += 1
}
for i in 1...10_000 where values[i] > 0{
result += String(repeating: "\(i)\n", count: values[i])
}
print(result)
final class FileIO {
private var buffer:[UInt8]
private var index: Int
init(fileHandle: FileHandle = FileHandle.standardInput) {
buffer = Array(fileHandle.readDataToEndOfFile())+[UInt8(0)]
index = 0
}
@inline(__always) private func read() -> UInt8 {
defer { index += 1 }
return buffer.withUnsafeBufferPointer { $0[index] }
}
@inline(__always) func readInt() -> Int {
var sum = 0
var now = read()
var isPositive = true
while now == 10
|| now == 32 { now = read() }
if now == 45{ isPositive.toggle(); now = read() }
while now >= 48, now <= 57 {
sum = sum * 10 + Int(now-48)
now = read()
}
return sum * (isPositive ? 1:-1)
}
@inline(__always) func readString() -> String {
var str = ""
var now = read()
while now == 10
|| now == 32 { now = read() }
while now != 10
&& now != 32 && now != 0 {
str += String(bytes: [now], encoding: .ascii)!
now = read()
}
return str
}
}