[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/python] ์œ„ํด๋ฆฌ ์ฑŒ๋ฆฐ์ง€ 4์ฃผ์ฐจ : ์ง์—…๊ตฐ ์ถ”์ฒœํ•˜๊ธฐ

2021. 8. 23. 19:30

๋ฌธ์ œ ์„ค๋ช…

๊ฐœ๋ฐœ์ž๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์–ธ์–ด์™€ ์–ธ์–ด ์„ ํ˜ธ๋„๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ทธ์— ๋งž๋Š” ์ง์—…๊ตฐ์„ ์ถ”์ฒœํ•ด์ฃผ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ฐœ๋ฐœํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ํ‘œ๋Š” 5๊ฐœ ์ง์—…๊ตฐ ๋ณ„๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” 5๊ฐœ ์–ธ์–ด์— ์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜๋ฅผ ๋ถ€์—ฌํ•œ ํ‘œ์ž…๋‹ˆ๋‹ค.

์ ์ˆ˜SICONTENTSHARDWAREPORTALGAME

5 JAVA JAVASCRIPT C JAVA C++
4 JAVASCRIPT JAVA C++ JAVASCRIPT C#
3 SQL PYTHON PYTHON PYTHON JAVASCRIPT
2 PYTHON SQL JAVA KOTLIN C
1 C# C++ JAVASCRIPT PHP JAVA

์˜ˆ๋ฅผ ๋“ค๋ฉด, SQL์˜ SI ์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜๋Š” 3์ ์ด์ง€๋งŒ CONTENTS ์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜๋Š” 2์ ์ž…๋‹ˆ๋‹ค. SQL์˜ HARDWARE, PORTAL, GAME ์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜๋Š” 0์ ์ž…๋‹ˆ๋‹ค.

์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜๋ฅผ ์ •๋ฆฌํ•œ ๋ฌธ์ž์—ด ๋ฐฐ์—ด table, ๊ฐœ๋ฐœ์ž๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์–ธ์–ด๋ฅผ ๋‹ด์€ ๋ฌธ์ž์—ด ๋ฐฐ์—ด languages, ์–ธ์–ด ์„ ํ˜ธ๋„๋ฅผ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด preference๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์–ธ์–ด์˜ ์–ธ์–ด ์„ ํ˜ธ๋„ x ์ง์—…๊ตฐ ์–ธ์–ด ์ ์ˆ˜์˜ ์ดํ•ฉ์ด ๊ฐ€์žฅ ๋†’์€ ์ง์—…๊ตฐ์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ดํ•ฉ์ด ๊ฐ™์€ ์ง์—…๊ตฐ์ด ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๊ฒฝ์šฐ, ์ด๋ฆ„์ด ์‚ฌ์ „ ์ˆœ์œผ๋กœ ๊ฐ€์žฅ ๋น ๋ฅธ ์ง์—…๊ตฐ์„ return ํ•ด์ฃผ์„ธ์š”.

 

์ œํ•œ์‚ฌํ•ญ

  • table์˜ ๊ธธ์ด = 5
    • table์˜ ์›์†Œ๋Š” "์ง์—…๊ตฐ 5์ ์–ธ์–ด 4์ ์–ธ์–ด 3์ ์–ธ์–ด 2์ ์–ธ์–ด 1์ ์–ธ์–ด"ํ˜•์‹์˜ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ์ง์—…๊ตฐ, 5์ ์–ธ์–ด, 4์–ธ์–ด, 3์ ์–ธ์–ด, 2์ ์–ธ์–ด, 1์ ์–ธ์–ด๋Š” ํ•˜๋‚˜์˜ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • table์€ ๋ชจ๋“  ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์—์„œ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
  • 1 ≤ languages์˜ ๊ธธ์ด ≤ 9
    • languages์˜ ์›์†Œ๋Š” "JAVA", "JAVASCRIPT", "C", "C++" ,"C#" , "SQL", "PYTHON", "KOTLIN", "PHP" ์ค‘ ํ•œ ๊ฐœ ์ด์ƒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • languages์˜ ์›์†Œ๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • preference์˜ ๊ธธ์ด = languages์˜ ๊ธธ์ด
    • 1 ≤ preference์˜ ์›์†Œ ≤ 10
  • preference์˜ i๋ฒˆ์งธ ์›์†Œ๋Š” languages์˜ i๋ฒˆ์งธ ์›์†Œ์˜ ์–ธ์–ด ์„ ํ˜ธ๋„์ž…๋‹ˆ๋‹ค.
  • return ํ•  ๋ฌธ์ž์—ด์€ "SI", "CONTENTS", "HARDWARE", "PORTAL", "GAME" ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

 

์ •๋‹ต

def solution(table, languages, preference):
    answer = []
    new_table = sorted([list(t.split()) for t in table], key=lambda x : x[0])
    job = {n: new_table[n][0] for n in range(len(new_table))}

    for j in range(len(job)):
        total = 0
        for lang, pref in zip(languages, preference):
            if lang in new_table[j]:
                total += (6 - new_table[j].index(lang)) * pref
        answer.append(total)

    return job[answer.index(max(answer))]

โœ” table ๋ฆฌ์ŠคํŠธ ์ด์ฐจ์› ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ ํ›„ ์ด์šฉํ•˜๊ธฐ

โœ” ์ฒ˜์Œ๋ถ€ํ„ฐ table์„ ์ง์—…๊ตฐ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ ํ›„ ์ด์šฉํ•˜๊ธฐ

โœ” table์˜ index๋Š” ์ ์ˆ˜์™€ ๋ฐ˜๋Œ€์ด๊ธฐ ๋•Œ๋ฌธ์— 6-index๋กœ ๊ณ„์‚ฐํ•˜๊ธฐ

728x90

BELATED ARTICLES

more