Bibi's DevLog ๐ค๐
[๋ฐฑ์ค 2484] ์ฃผ์ฌ์ ๋ค๊ฐ (Swift) ๋ณธ๋ฌธ
ํ๋ก๊ทธ๋๋ฐ/์๊ณ ๋ฆฌ์ฆ ํ์ด Swift
[๋ฐฑ์ค 2484] ์ฃผ์ฌ์ ๋ค๊ฐ (Swift)
๋น๋น bibi 2022. 9. 12. 12:08- 2476 ์ฃผ์ฌ์ ๊ฒ์ ๊ณผ ๋น์ทํ๊ฒ ํ๋ฉด ๋๊ฒ ๋ค๊ณ ์๊ฐํ๋๋ฐ, ๊ฒฝ์ฐ์ ์๊ฐ ํจ์ฌ ๋ ๋ง์๋ค.
- filter๋ฅผ ํ์ฉํด ๋์จ ์ฃผ์ฌ์ ๋์ ๋ชจ๋ ํ์ํด์ ๊ฐ์ ๋์ด ๋ช ๊ฐ์ธ์ง ๊ตฌํ ๋ค, ๊ทธ์ ๋ฐ๋ผ ์๊ธ์ ๊ณ์ฐํ๋ค
- ๊ฐ์ ๋์ด ๋ช ๊ฐ์ธ์ง ๊ตฌํ๋ฉด์, ๊ฐ์ ๋์ธ ์ซ์๊ฐ ๋ฌด์์ธ์ง๋ ์ ์ฅํจ
- ๊ฐ์ ๋์ด 2๊ฐ์ธ ๊ฒฝ์ฐ, ์ด๋ฏธ ์ฐพ์ ๊ฐ์ ๋ 2๊ฐ๋ฅผ ์ ์ธํ ๋๋จธ์ง ๋ฐฐ์ด(๊ธธ์ด=2)์ ๊ฐ์ด ์๋ก ๊ฐ์ผ๋ฉด 2์์ผ๋ก ํ๋จํ๊ณ , ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ํ ์์ผ๋ก ํ๋จํ๋ค.
ํ์ด
let count = Int(readLine()!)!
var answer = 0
(1...count).forEach { _ in
let inputArr = readLine()!.split(separator: " ").map { Int($0)! }
var prize = 0
var equalCount = 0
var equalNum = 0
for index in 0..<4 {
let count = inputArr.filter { $0 == inputArr[index] }.count
if count > equalCount {
equalCount = count
equalNum = inputArr[index]
}
}
switch equalCount {
case 4:
prize = 50000 + equalNum * 5000
case 3:
prize = 10000 + equalNum * 1000
case 2:
let partialArr = inputArr.filter { $0 != equalNum }
if partialArr[0] == partialArr[1] {
let anotherEqualNum = partialArr[0]
prize = 2000 + equalNum * 500 + anotherEqualNum * 500
} else {
prize = 1000 + equalNum * 100
}
case 1:
prize = inputArr.max()! * 100
default:
return
}
if prize > answer {
answer = prize
}
}
print(answer)
'ํ๋ก๊ทธ๋๋ฐ > ์๊ณ ๋ฆฌ์ฆ ํ์ด Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 2562] ์ต๋๊ฐ (Swift) (0) | 2022.09.14 |
---|---|
[๋ฐฑ์ค 2490] ์ท๋์ด (1) | 2022.09.13 |
[๋ฐฑ์ค 2476] ์ฃผ์ฌ์ ๊ฒ์ (Swift) (0) | 2022.09.09 |
[๋ฐฑ์ค 2309] ์ผ๊ณฑ ๋์์ด (0) | 2022.09.07 |
[๋ฐฑ์ค 2386] ๋๋น์ ์์ด ๊ณต๋ถ (0) | 2022.09.07 |