Bibi's DevLog ๐Ÿค“๐ŸŽ

[๋ฐฑ์ค€ 3047] ABC (Swift) ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด Swift

[๋ฐฑ์ค€ 3047] ABC (Swift)

๋น„๋น„ bibi 2022. 10. 12. 11:59

3047๋ฒˆ: ABC

์ฒซ ์ค„ ์ž…๋ ฅ์—์„œ A < B < C ์ธ ์ˆ˜ A, B, C๋ฅผ ์ฐพ๊ณ 

๋‘๋ฒˆ์งธ ์ค„ ์ž…๋ ฅ์—์„œ ์ฃผ์–ด์ง€๋Š” ์ˆœ์„œ๋Œ€๋กœ A, B, C๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ

  • ์ฒซ ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ Int๋กœ ์บ์ŠคํŒ… ์•ˆํ•ด๋„ ๋˜๋‚˜? ํ•ด์„œ ์•ˆํ–ˆ๋Š”๋ฐ, ๊ทธ๊ฑด ํ•œ ์ž๋ฆฌ ์ˆ˜ ๊ธฐ์ค€์—์„œ๋งŒ ์„ฑ๋ฆฝํ•˜๊ณ , ์—ฌ๋Ÿฌ ์ž๋ฆฌ ์ˆ˜ ์ •๋ ฌํ•  ๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ Int๋กœ ๋ณ€ํ™˜ํ•ด์ค˜์•ผ ํ–ˆ๋‹ค.
    • String ์ •๋ ฌ : 1, 4, 3 โ†’ 1, 3, 4 (O) / 1, 9, 11 โ†’ 1, 11, 9 (X)
    • Int ์ •๋ ฌ : 1, 4, 3 โ†’ 1, 3, 4 (O) / 1, 9, 11 โ†’ 1, 9, 11 (O)

ํ’€์ด

var input = readLine()!.split(separator: " ").map { Int($0)! }
input = input.sorted()
let order = readLine()!
for char in order {
    switch char {
    case "A":
        print(input[0], terminator: " ")
    case "B":
        print(input[1], terminator: " ")
    case "C":
        print(input[2], terminator: " ")
    default:
        break
    }
}