xCode로 백준 문제 기본 세팅

힐링힐링·2023년 9월 16일
0

테크잇

목록 보기
7/19
post-thumbnail

xCode 프로젝트 생성 및 백준 문제를 풀기위한 세팅

new project를 누르고 command line tool를 클릭

프로젝트 생성

Algorithm 폴더 우클릭후 내부에 BackJoon, Programmers 폴더 생성

백준 문제 1000번을 푼다는 가정하에 파일 생성

main.swift를 Baekjoon폴더에 옮김
프로젝트당 main.swift는 하나로 고정되기 때문
main에서 1000번 푼뒤, 1000.swift파일 생성후에 소스 붙여버리자.

main에는 해당 소스가 있는데 input 값을 집어넣고 뿌려주는 역활

var input = readLine()

if let input = input {
    let inputs = input.components(separatedBy: " ")
    print(inputs)
}

terminator 를 통해 input 값을 입력할수 있다.
백준에서 예제를 복사해서 terminator에 입력하면서 활용할수 있다는 뜻.

import Foundation

print("예제 : ", terminator:  "")

var input = readLine()

if let input = input {
    let inputs = input.components(separatedBy: " ")
    print(inputs)
}

//print("hello world")

1000번 문제 답

import Foundation

//print("예제 : ", terminator:  "")

var input = readLine()

if let input = input {
    let inputs = input.components(separatedBy: " ")
//    print(inputs)
    let A = Int(inputs[0])!
    let B = Int(inputs[1])!
    print(A + B)
}
profile
재밌겠네 ? 해봐야지 ~

0개의 댓글