๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution/Programmers

[Swift] 2021 KAKAO BLIND RECRUITMENT ์ˆœ์œ„ ๊ฒ€์ƒ‰

by Fomagran ๐Ÿ’ป 2021. 3. 18.
728x90
๋ฐ˜์‘ํ˜•

Foma's ํ’€์ด

 

๋ชจ๋“  ์ง€์›์ž๋“ค์€ ์–ธ์–ด, ์ง๊ตฐ, ๊ฒฝ๋ ฅ, ์†Œ์šธํ‘ธ๋“œ, ์ ์ˆ˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด ์ •๋ณด๋ฅผ ๊ฐ–๊ธฐ ์œ„ํ•ด์„œ ๋„์–ด์“ฐ๊ธฐ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ„์–ด์„œ ๋ฐฐ์—ด์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. 

 

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด 0๋ฒˆ์งธ ์–ธ์–ด 1๋ฒˆ์งธ ์ง๊ตฐ 2๋ฒˆ์งธ ๊ฒฝ๋ ฅ 2๋ฒˆ์งธ ์†Œ์šธํ‘ธ๋“œ 4๋ฒˆ์งธ ์ ์ˆ˜๊ฐ€ ๋  ๊ฒƒ ์ž…๋‹ˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ๋‚˜๋ˆ„์–ด์ง„ ์ง€์›์ž๋“ค์„ ์ ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ค๋‹ˆ๋‹ค.

 

๊ทธ ๋‹ค์Œ์œผ๋ก  ์ œ๊ฐ€ ํ•ต์‹ฌ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š” ์ฒซ๋ฒˆ์งธ์ž…๋‹ˆ๋‹ค. (๋„์ €ํžˆ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์นด์นด์˜ค ๋ฌธ์ œํ•ด์„ค์„ ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค.....)

 

์ง€์›์ž๋“ค์˜ 4๊ฐ€์ง€ ์ •๋ณด๋กœ ๋ชจ๋“  ์ผ€์ด์Šค๋“ค์„ 16๊ฐ€์ง€๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋ฒ„๋ฆฌ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค๋ฉด ์ž๋ฐ” ๋ฐฑ์—”๋“œ ์‹œ๋‹ˆ์–ด ํ”ผ์ž๋ผ๋ฉด 

 

์ •๋ณด์—†์Œ

์ž๋ฐ”

์ž๋ฐ” ๋ฐฑ์—”๋“œ

์ž๋ฐ” ์‹œ๋‹ˆ์–ด

์ž๋ฐ” ํ”ผ์ž

์ž๋ฐ” ๋ฐฑ์—”๋“œ ์‹œ๋‹ˆ์–ด

์ž๋ฐ” ๋ฐฑ์—”๋“œ ํ”ผ์ž

์ž๋ฐ” ์‹œ๋‹ˆ์–ด ํ”ผ์ž

์ž๋ฐ” ๋ฐฑ์—”๋“œ ์‹œ๋‹ˆ์–ด ํ”ผ์ž

๋ฐฑ์—”๋“œ

๋ฐฑ์—”๋“œ ์‹œ๋‹ˆ์–ด

๋ฐฑ์—”๋“œ ํ”ผ์ž

๋ฐฑ์—”๋“œ ์‹œ๋‹ˆ์–ด ํ”ผ์ž

์‹œ๋‹ˆ์–ด

์‹œ๋‹ˆ์–ด ํ”ผ์ž

ํ”ผ์ž

 

๊ฐ€ ๋˜๊ฒ ์ฃ .

 

์ด๋Ÿฐ์‹์œผ๋กœ ๊ฐ ์ง€์›์ž๋“ค์„ 16๊ฐ€์ง€ ๊ทธ๋ฃน์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์ ์ˆ˜๋“ค๋งŒ ๋”ฐ๋กœ ์ €์žฅํ•ด์ค๋‹ˆ๋‹ค.

 

๊ทธ ๋‹ค์Œ ์ฟผ๋ฆฌ๊ฐ€ ์ฃผ์–ด์กŒ์„๋•Œ ๋™์ผํ•œ ๊ทธ๋ฃน์˜ ์ ์ˆ˜๋“ค๋งŒ ๋น„๊ตํ•ด์„œ ์นด์šดํŒ… ํ•ด์ค๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ์„œ ์ œ๊ฐ€ ํ•ต์‹ฌ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š” 2๋ฒˆ์งธ๋Š” ์ด์ง„ํƒ์ƒ‰ ์ž…๋‹ˆ๋‹ค.

 

๋™์ผํ•œ ๊ทธ๋ฃน์˜ ์ ์ˆ˜๋“ค์ด ์•„์ฃผ ๋งŽ์„ ๋• ํšจ์œจ์ ์œผ๋กœ ์ด์ง„ํƒ์ƒ‰์œผ๋กœ ๊ฐ’๋“ค์„ ๋น„๊ตํ•ด์„œ ์นด์šดํŒ…ํ•ด์ค˜์•ผํ•ฉ๋‹ˆ๋‹ค. (์•ˆ๊ทธ๋Ÿผ ํšจ์œจ์„ฑ ๋‹คํ‹€๋ฆผ..)

 

๋งˆ์ง€๋ง‰์œผ๋กœ ์ฟผ๋ฆฌ์˜ ๋ชจ๋“  ์กฐ๊ฑด์— ๋งž๋Š” ์ง€์›์ž๋“ค์˜ ์ˆ˜๋ฅผ ๋ฐฐ์—ด์— ๋‹ด์•„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


Source Code

 

 


ํ‹€๋ ธ๋˜ ์ผ€์ด์Šค๋“ค

1์ฐจ ์‹œ๋„

 

์ •ํ™•์„ฑ์€ ๋ชจ๋‘ ๋งž์•˜์ง€๋งŒ ํšจ์œจ์„ฑ์—์„œ ๋‹ค ํ‹€๋ฆฐ ์ฝ”๋“œ

 

๋‚˜๋ฆ„ ์ด ์ฝ”๋“œ๋ฅผ ์“ธ ๋•Œ๋„ 4๊ฐ€์ง€ ์ •๋ณด๋กœ ์ž˜๋ผ์„œ ํšจ์œจ์ ์œผ๋กœ ๋น„๊ตํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ..... 

import Foundation

func solution(_ info:[String], _ query:[String]) -> [Int] {

    var counts = [Int]()
    var applicants = [[String]]()
    info.forEach{applicants.append($0.components(separatedBy: " "))}
    let sortedApplicants = applicants.sorted{Int($0[4])! > Int($1[4])!}
    
    for q in query {
        var count = 0
        let split = q.replacingOccurrences(of: "and", with: "").replacingOccurrences(of: "-", with: "").components(separatedBy: " ").filter{$0 != ""}
        var filterApplicant = sortedApplicants
        for (i,s) in split.enumerated() {
            if i == split.count - 1 {
                for applicant in filterApplicant {
                    if Int(applicant[4])! >= Int(String(split.last!))! {
                        count += 1
                    }else {
                        break
                    }
                }
                counts.append(count)
            }else {
                if s == "backend" || s == "frontend" {
                    filterApplicant = filterApplicant.filter{$0[1] == s}
                }else if s == "junior" || s == "senior"  {
                    filterApplicant = filterApplicant.filter{$0[2] == s}
                }else if s == "pizza" || s == "chicken" {
                    filterApplicant = filterApplicant.filter{$0[3] == s}
                }else {
                    filterApplicant = filterApplicant.filter{$0[0] == s}
                }
            }
        }
    }
    
    return counts
}

2์ฐจ ์‹œ๋„

 

๋ชจ๋“  ์ผ€์ด์Šค๋“ค์„ ๋ชจ์•„์„œ ๋Œ๋ฆฌ๊ธด ํ–ˆ์ง€๋งŒ ์ด์ง„ ํƒ์ƒ‰์„ ์“ฐ์ง€ ์•Š์•„ ๋ชจ๋“  ํšจ์œจ์„ฑ์—์„œ ๋‹ค ํ‹€๋ฆผ.

func solution(_ info:[String], _ query:[String]) -> [Int] {

    var counts = [Int]()
    var applicants = [[String]]()
    info.forEach{applicants.append($0.components(separatedBy: " "))}
    applicants.sort{Int($0[4])! > Int($1[4])!}
    
    var language = String()
    var backOrFront = String()
    var career = String()
    var food = String()
    
    var caseDic = [String:[Int]]()
    
    for applicant in applicants {
        language = applicant[0]
        backOrFront = applicant[1]
        career = applicant[2]
        food = applicant[3]
        let allCases = ["- and - and - and -",
                   "- and - and - and \(food)",
                   "- and - and \(career) and -",
                   "- and \(backOrFront) and - and -",
                   "\(language) and - and - and -",
                   "\(language) and - and - and \(food)",
                   "\(language) and \(backOrFront) and - and -",
                   "\(language) and - and \(career) and -",
                   "- and \(backOrFront) and \(career) and -",
                   "- and \(backOrFront) and - and \(food)",
                   "- and - and \(career) and \(food)",
                   "\(language) and \(backOrFront) and \(career) and -",
                   "\(language) and \(backOrFront) and - and \(food)",
                   "\(language) and - and \(career) and \(food)",
                   "- and \(backOrFront) and \(career) and \(food)",
                   "\(language) and \(backOrFront) and \(career) and \(food)"]
        for i in 0..<allCases.count {
            if caseDic[allCases[i]] != nil {
                caseDic[allCases[i]]!.append(Int(applicant[4])!)
            }else{
                caseDic[allCases[i]] = [Int(applicant[4])!]
            }
        }
    }
    
    for q in query {
        var count = 0
        var split = q.components(separatedBy: " ")
        let score = Int(split.removeLast())!
        let join = String(split.joined(separator: " "))
        if caseDic[join] == nil {
            counts.append(0)
        }else {
            for number in caseDic[join]! {
                if number >= score {
                    count += 1
                }else{
                    break
                }
            }
            counts.append(count)
        }
    }
    
    return counts
}

 


Reference

 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ˆœ์œ„ ๊ฒ€์ƒ‰

["java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"] ["java and backend and junior and pizza 100","pyt

programmers.co.kr

 

2021 ์นด์นด์˜ค ์‹ ์ž…๊ณต์ฑ„ 1์ฐจ ์˜จ๋ผ์ธ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ for Tech developers ๋ฌธ์ œํ•ด์„ค

์ง€๋‚œ 2020๋…„ 9์›” 12์ผ ํ† ์š”์ผ ์˜คํ›„ 2์‹œ๋ถ€ํ„ฐ 7์‹œ๊นŒ์ง€ 5์‹œ๊ฐ„ ๋™์•ˆ 2021 ์นด์นด์˜ค ์‹ ์ž… ๊ฐœ๋ฐœ์ž ๊ณต์ฑ„ 1์ฐจ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๊ฐ€ ์ง„ํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ…Œ์ŠคํŠธ์—๋Š” ์ด 7๊ฐœ์˜ ๋ฌธ์ œ๊ฐ€ ์ถœ์ œ๋˜์—ˆ์œผ๋ฉฐ, ๊ฐœ๋ฐœ ์–ธ์–ด๋Š” C++, Java, Jav

tech.kakao.com

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€