본문 바로가기

BOJ알고리즘

BOJ 2920 with Swift

반응형

BOJ 2920 with Swift

2920번: 음계

문제

  • 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다.
  • 1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다.
  • 연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.

입력값

1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 8 1 7 2 6 3 5 4

출력값

ascending descending mixed

코드

import Foundation

struct Q2920 {
    static let ascending = ["1","2","3","4","5","6","7","8"]
    static let descending = ["8","7","6","5","4","3","2","1"]

    static func main(){
        if let read = readLine() {
            let numbers = read.components(separatedBy: " ")
            switch numbers {
            case ascending :
                print("ascending")
            case descending :
                print("descending")
            default :
                print("mixed")
            }
        }
    }
}


Q2920.main()
반응형

'BOJ알고리즘' 카테고리의 다른 글

BOJ 11654 with Swift  (0) 2018.09.02
BOJ 10809 with Swift  (0) 2018.09.02
BOJ 10039 with Swift  (0) 2018.09.02
BOJ 8958 with Swift  (0) 2018.09.02
BOJ 2577 with Swift  (0) 2018.09.02