일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 예외처리
- label
- BAEKJOON
- android java
- storyboard
- 플러터
- 버블정렬
- Firebase
- 보호와 보안
- deeplink
- Xcode
- text to speech
- IOS
- Android
- C언어
- TextField
- 안드로이드스튜디오
- swift baekjoon
- 준코딩
- FLUTTER
- 백준
- 자바
- 연결리스트
- customPopup
- Android Studio
- xocde
- Swift
- 안드로이드
- 커스텀팝업
- 링크드리스트
Archives
- Today
- Total
준코딩
[Swift] 백준 15552번 문제 빠른 A+B 본문
https://www.acmicpc.net/problem/15552
15552번: 빠른 A+B
첫 줄에 테스트케이스의 개수 T가 주어진다. T는 최대 1,000,000이다. 다음 T줄에는 각각 두 정수 A와 B가 주어진다. A와 B는 1 이상, 1,000 이하이다.
www.acmicpc.net
https://github.com/Ljunhyeob/baekjoon15552
GitHub - Ljunhyeob/baekjoon15552: 백준 - 15552
백준 - 15552. Contribute to Ljunhyeob/baekjoon15552 development by creating an account on GitHub.
github.com
import Foundation
// 라이노님의 FileIO
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
}
}
// 풀이
var answer = ""
func solution() {
let a = file.readInt(), b = file.readInt()
answer += "\(a + b)\n"
}
let file = FileIO()
let n = file.readInt()
for _ in 0..<n {
solution()
}
print(answer)
'알고리즘 > Swift 백준 문제풀이' 카테고리의 다른 글
[Swift] 백준 11022번 문제 A+B - 8 (0) | 2023.01.05 |
---|---|
[Swift] 백준 11021번 문제 A+B - 7 (0) | 2023.01.05 |
[Swift] 백준 25304번 문제 영수증 (0) | 2023.01.05 |
[Swift] 백준 8393번 문제 합 (0) | 2023.01.05 |
[Swift] 백준 10950번 문제 A+B - 3 (0) | 2023.01.05 |
Comments