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

[๋ฐฑ์ค€ 2484] ์ฃผ์‚ฌ์œ„ ๋„ค๊ฐœ (Swift) ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 2484] ์ฃผ์‚ฌ์œ„ ๋„ค๊ฐœ (Swift)

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

2484๋ฒˆ: ์ฃผ์‚ฌ์œ„ ๋„ค๊ฐœ

  • 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)