Bibi's DevLog ๐ค๐
[๋ฐฑ์ค 2966] ์ฐ๊ธฐ (Swift) ๋ณธ๋ฌธ
ํ๋ก๊ทธ๋๋ฐ/์๊ณ ๋ฆฌ์ฆ ํ์ด Swift
[๋ฐฑ์ค 2966] ์ฐ๊ธฐ (Swift)
๋น๋น bibi 2022. 9. 29. 12:12ํ๋ก๊ทธ๋๋จธ์ค์ โ๋ชจ์๊ณ ์ฌโ๋ฌธ์ ์ ๊ฑฐ์ ๋์ผํ๋ค. (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")
}
'ํ๋ก๊ทธ๋๋ฐ > ์๊ณ ๋ฆฌ์ฆ ํ์ด Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 3035] ์ค์บ๋ (Swift) (1) | 2022.10.05 |
---|---|
[๋ฐฑ์ค 3004] ์ฒด์คํ ์กฐ๊ฐ (3) | 2022.09.30 |
[๋ฐฑ์ค 2953] ๋๋ ์๋ฆฌ์ฌ๋ค (Swift) (0) | 2022.09.29 |
[๋ฐฑ์ค 2947] ๋๋ฌด ์กฐ๊ฐ (0) | 2022.09.28 |
[๋ฐฑ์ค 2846] ์ค๋ฅด๋ง๊ธธ (Swift) (0) | 2022.09.23 |