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

[๋ฐฑ์ค€ 2966] ์ฐ๊ธฐ (Swift) ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 2966] ์ฐ๊ธฐ (Swift)

๋น„๋น„ bibi 2022. 9. 29. 12:12

2966๋ฒˆ: ์ฐ๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ โ€˜๋ชจ์˜๊ณ ์‚ฌโ€™๋ฌธ์ œ์™€ ๊ฑฐ์˜ ๋™์ผํ•˜๋‹ค. (https://school.programmers.co.kr/learn/courses/30/lessons/42840)

  • ์ •ํ•ด์ง„ ํŒจํ„ด๋Œ€๋กœ ์ฐ์—ˆ์„ ๋•Œ ๋ˆ„๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์ ์ˆ˜๋ฅผ ๋ฐ›๋Š”์ง€ ์ถœ๋ ฅ
  • ๋™์ ์ž๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ max๋ฅผ ์ฐพ์•„ ๊ฐ ์ธ์›์˜ ์ ์ˆ˜์™€ ๋น„๊ตํ–ˆ๋‹ค
    • ๋™์ ์ž์˜ ๊ฒฝ์šฐ ์ฃผ์–ด์ง„ ์ด๋ฆ„ ์ˆœ์„œ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์•ผ ํ•จ
  • ํŒจํ„ด์€ ๋ฐ˜๋ณต๋˜๋Š” ๋ถ€๋ถ„๊นŒ์ง€ ํ•˜๋“œ์ฝ”๋”ฉ ํ›„, ์ธ๋ฑ์Šค๋ฅผ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ์ž๋ฅผ ํ™œ์šฉํ•œ๋‹ค.

ํ’€์ด

let count = Int(readLine()!)!
let answers = readLine()!.map { String($0) }
let student1 = ["A", "B", "C"]
let student2 = ["B", "A", "B", "C"]
let student3 = ["C", "C", "A", "A", "B", "B"]
var student1Score = 0
var student2Score = 0
var student3Score = 0
for number in (0..<count) {
    let answer = answers[number]
    if answer == student1[number % student1.count] {
        student1Score += 1
    }
    if answer == student2[number % student2.count] {
        student2Score += 1
    }
    if answer == student3[number % student3.count] {
        student3Score += 1
    }
}
let maxScore = max(student1Score, student2Score, student3Score)
print(maxScore)
if maxScore == student1Score {
    print("Adrian")
}
if maxScore == student2Score {
    print("Bruno")
}
if maxScore == student3Score {
    print("Goran")
}