일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- LEVEL 2
- Code Jam
- nestedlists
- 방송통신대학교 대학원 정보과학과
- ingress-nginx
- 방통대 대학원 정보과학과
- Qualification Round
- secondlowestgrade
- 프로그래머스
- 해커랭크
- MySQL
- 하늘과 바람과 별과 詩
- Code Jam 2022
- hackerrank
- 하늘과 바람과 별과 시
- ESXi 업데이트
- 코딩테스트
- on-prem
- Python
- 2022
- GitLab
- 3D PRINTING
- swift
- 파이썬
- Kubernetes
- 정보과학과
- K8S
- openebs
- C++
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 1] 모의고사 Swift 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/42840
풀이는 추후에 차차 올리도록 하겠습니다...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import Foundation
func solution(\_ answers:\[Int\]) -> \[Int\] {
var scores: \[Int:Int\] = \[Int:Int\]()
let ans\_1: \[Int\] = \[Int\](1...5)
let ans\_2: \[Int\] = \[2, 1, 2, 3, 2, 4, 2, 5\]
let ans\_3: \[Int\] = \[3, 3, 1, 1, 2, 2, 4, 4, 5, 5\]
for i in 0..<answers.count {
let ans: Int = answers\[i\]
scores\[1\] = (ans == ans\_1\[i%5\] ? (scores\[1\] ?? 0) + 1 : scores\[1\])
scores\[2\] = (ans == ans\_2\[i%8\] ? (scores\[2\] ?? 0) + 1 : scores\[2\])
scores\[3\] = (ans == ans\_3\[i%10\] ? (scores\[3\] ?? 0) + 1 : scores\[3\])
}
return scores.filter { $0.value == scores.values.max() }.keys.sorted()
}
|
cs |
'Programming Language > Swift' 카테고리의 다른 글
[프로그래머스][Lv. 1] 약수의 개수와 덧셈 Swift 풀이 (0) | 2022.03.14 |
---|---|
[프로그래머스][Lv. 1] 체육복 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] K번째 수 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 소수 만들기 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 내적 Swift 풀이 (0) | 2022.03.14 |
Comments