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

[๋ฐฑ์ค€ 11586] ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ๋งˆ๋ฒ• ๊ฑฐ์šธ (Swift) ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 11586] ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ๋งˆ๋ฒ• ๊ฑฐ์šธ (Swift)

๋น„๋น„ bibi 2023. 1. 30. 17:17

11586๋ฒˆ: ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ๋งˆ๋ฒ• ๊ฑฐ์šธ

์ฃผ์–ด์ง€๋Š” N*N์˜ ๋ฌธ์ž์—ด์„ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋ณ€ํ˜•ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

  • K = 1 : ์ž…๋ ฅ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅ
  • K = 2 : ์ขŒ์šฐ๋ฐ˜์ „๋œ ๋ชจ์Šต์œผ๋กœ ์ถœ๋ ฅ
  • K = 3 : ์ƒํ•˜๋ฐ˜์ „๋œ ๋ชจ์Šต์œผ๋กœ ์ถœ๋ ฅ

ํ’€์ด

์šฐ์„  ์ž…๋ ฅ๊ฐ’์„ String ๋ฐฐ์—ด์— ๋„ฃ๋Š”๋‹ค.

  • 1์ผ ๋•Œ๋Š” ์ž…๋ ฅ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค.
  • 2์ผ ๋•Œ๋Š” ๋ฐฐ์—ด์˜ ์š”์†Œ ํ•˜๋‚˜(๋ฌธ์ž์—ด)์„ ๋’ค์ง‘์–ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.
    • reversed() ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ–ˆ๋‹ค.
  • 3์ผ ๋•Œ๋Š” ๋ฐฐ์—ด์˜ ๋ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ์ฒซ ์ธ๋ฑ์Šค ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•œ๋‹ค.
    • ๋ฐฐ์—ด์— ์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ•˜๋ฏ€๋กœ ์ฆ‰์‹œ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค
let count = Int(readLine()!)!
var mirror: [String] = []
(1...count).forEach { _ in
    mirror.append(readLine()!)
}
let option = Int(readLine()!)!

if option == 1 {
    mirror.forEach { print($0) }
}
if option == 2 {
    mirror.forEach { print(String($0.reversed())) }
}
if option == 3 {
    for index in mirror.indices {
        let revesredIndex = mirror.count - 1 - index
        print(mirror[revesredIndex])
    }
}