전체 글
백준에서 코테를 준비하는데 값을 가져올 때 readLine() 함수를 많이 사용해서 readLine에 관하여 포스팅하려 한다.readLine()Returns a string read from standard input through the end of the current line or until EOF is reached.→ 현재 줄의 끝 또는 EOF(End Of File)에 도달할 때까지 표준 입력에서 읽은 문자열을 반환합니다. XCode에서 사용 방법1) 프로젝트 생성 - macOS [Command Line Tool]로 생성 단일 문자열 받아오기import Foundationlet a = readLine()!print(a) 결과는 처음 커서에 원하는 값을 입력하면 출력할 수 있다. 여러 문자열 받아..
문제https://www.acmicpc.net/problem/10951while let input = readLine()?.split(separator: " ").map({ Int($0)! }) { let a = input[0], b = input[1] print(a + b)} 출처 [BOJ] 백준 10951 A+B - 4 (Swift)문제 https://www.acmicpc.net/problem/10951 10951번: A+B - 4 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. www.acmicpc.net 풀이 Swift에서 cmd + D 를 입력해서 EOF를 입력시킬 수 있음 EOF가dev-mandos.tistory.com
문제https://www.acmicpc.net/problem/10952import Foundationvar arr: [Int] = []while true{ let line = readLine()! let lineArr = line.components(separatedBy: " ") let a = Int(lineArr[0])! let b = Int(lineArr[1])! if a==0 && b==0{ for i in 0.. 출처 [Swift] 백준 10952번 문제 A+B - 5https://www.acmicpc.net/problem/10952 10952번: A+B - 5 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. www.acmicp..
List하나의 열에 여러 개의 행으로 표현되는 UI를 구성해 다중 데이터를 쉽게 나열할 수 있는 구성된 ViewUIKit에서 동일한 역할을 하던 UITableView와 비교적 사용법이 간소화 됨List{ ForEach(0.. 동적 콘텐츠에서 사용 방식Range 동적 콘텐츠로 Range 타입을 넘겨줌Half-Open Range Operator(Range) A.. 다른 범위 연산자는 사용 불가List(0..RandomAccessCollection Protocol1. id로 사용할 값을 직접 인수로 지정// Hashable 프로토콜 준수 시에는 간편하게 self로 사용List(["A", "B", "C", "D", "E"], id: \.self){ Text("\($0)")} 2. Identifiabl..
최대공약수// 최대공약수func gcd(_ a: Int, _ b: Int) -> Int{ if b == 0 { return a } else{ return gcd(b, a % b) }} 최소공배수// 최소공배수func lcm(_ a: Int, _ b: Int) -> Int{ return a * b / gcd(a, b)} 제곱수 구하기// pow 함수 두 인자 모두 소수점 형으로 변경해야 오류 발생하지 않음, 두 인자 모두 Double로 변환해서 사용가능func pow(_ x: Decimal, _ y: Int) -> Decimalfunc pow(_: Float, _: Float) -> Float 거듭제곱 구하기(루트)func sqrt(_: Double) -..