Algorithm/SWEA
[SWEA - D2] 1983. ์กฐ๊ต์ ์ฑ์ ๋งค๊ธฐ๊ธฐ
hello_u
2023. 4. 17. 22:43
๋์ ์ฝ๋
arr = ["A+" , "A0" , "A-" ,"B+" , "B0" , "B-" , "C+" ,"C0" , "C-", "D0"]
T = int(input())
# ์ฌ๋ฌ๊ฐ์ ํ
์คํธ ์ผ์ด์ค๊ฐ ์ฃผ์ด์ง๋ฏ๋ก, ๊ฐ๊ฐ์ ์ฒ๋ฆฌํฉ๋๋ค.
for t in range(1, T + 1):
n,k = map(int,input().split())
score = {}
for i in range(1,n+1):
a,b,c = map(int,input().split())
result = (a*0.35) + (b*0.45) + (c*0.2)
score[i] = result
sorted_score = dict(sorted(score.items() , key= lambda x : x[1] , reverse = True))
x = n//10 # x ๊ฐ์ฉ ํ์ ๋ถ์ฌ
cnt = 1
idx = 0
for key in sorted_score.keys():
sorted_score[key] = arr[idx]
if cnt == x:
idx += 1
cnt = 1
else:
cnt += 1
print("#"+str(t) , sorted_score[k] )
์ด์ ์ ๊ตฌํ ํ์ ํ์ ๋ฒํธ์ ํจ๊ป ๋์ ๋๋ฆฌ์ ์ ์ฅํ๋ค.
๊ทธ๋ฆฌ๊ณ ์ด์ ์ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
์ ๋ ฌ๋ ์์๋๋ก ๋์ ํ์ ์ ์ฐจ๋ก๋ก ๋ถ์ฌํ๋ค.
value ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํ ๋์ ๋๋ฆฌ ์์ฑํ๊ธฐ
dict(sorted(dic.items(), key=lambda x:x[1])))
๋ค๋ฅธ ์ฌ๋ ํ์ด
T = int(input())
grade = ['A+', 'A0', 'A-', 'B+', 'B0', 'B-', 'C+', 'C0', 'C-', 'D0']
for test_case in range(1, T + 1):
N, K = map(int, input().split())
cnt = N//10
student = []
for i in range(1, N+1):
semi, final, task = map(int, input().split())
score = semi * 0.35 + final * 0.45 + task * 0.2
student.append(score)
if i == K:
K = score
student.sort(reverse=True)
print('#%d %s' % (test_case, grade[student.index(K)//cnt]))
์ ์๋ฅผ ๋ฐฐ์ด๋ก ์์ฑํ๊ณ
ํ์ ์ ์๊ณ ์ถ์ ํ์์ ๋ฒํธ๋ฅผ ๋ณ์์ ์ ์ฅ
์ ์๋ฅผ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ ํ index ํจ์๋ฅผ ์ด์ฉํ์ฌ ํ์์ ํ์ ์ ์ฐพ๋๋ค.