티스토리 뷰

반응형


#. Problem 2480

* The copyright in this matter is in BOj



#. Resolution Process

  1. Read and understand problem

  2. Redefine the problem + abstract

  3. Create solution plan (select Algorithm, Data structure)

  4. Prove the plan (check performance time and usage memory)

  5. Carry out the plan

  6. Look back on the plan and find a way to improve it


#. Solve


 - 같은 눈이 3개가 나오면 10,000원+(같은 눈)*1,000원의 상금을 받게 된다. 

 - 같은 눈이 2개만 나오는 경우에는 1,000원+(같은 눈)*100원의 상금을 받게 된다. 

 - 모두 다른 눈이 나오는 경우에는 (그 중 가장 큰 눈)*100원의 상금을 받게 된다.  


#. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
lst = list(map(int, input().split()))
 
= len(set(lst))
if s == 3:
    print(max(lst) * 100)
elif s == 2:
    if lst.count(list(set(lst))[0]) == 2:
        print(1000 + list(set(lst))[0* 100)
    else:
        print(1000 + list(set(lst))[1* 100)
else:
    print(10000 + lst[0* 1000)
 
cs


너무 주먹구구식으로 짠 것 같긴 하지만...


#. Other Code

1
2
3
4
5
6
7
8
9
lst = sorted(list(map(int, input().split())))
 
= len(set(lst))
if s == 3:
    print(lst[2* 100)
elif s == 2:
    print(1000 + lst[1* 100)
else:
    print(10000 + lst[0* 1000)
cs


나는 무슨 바보같은 짓을 했는데.. 허허헣..

조금만 생각했더라면 이렇게 간단했을 것을..?


같은 눈이 2개일 경우를 보면,

2개의 눈이 같다면 정렬했을 때, 무조건 가운데 숫자가 중복되는 눈일 것이다.

왜?! 3개의 눈 중 2개의 눈이 중복되니깐..






#. Problem 2484

* The copyright in this matter is in BOj


#. Solve


- 같은 눈이 4개가 나오면 50,000원+(같은 눈)*5,000원의 상금을 받게 된다. 

- 같은 눈이 3개만 나오면 10,000원+(3개가 나온 눈)*1,000원의 상금을 받게 된다. 

- 같은 눈이 2개씩 두 쌍이 나오는 경우에는 2,000원+(2개가 나온 눈)*500원+(또 다른 2개가 나온 눈)*500원의 상금을 받게 된다.

- 같은 눈이 2개만 나오는 경우에는 1,000원+(같은 눈)*100원의 상금을 받게 된다. 

- 모두 다른 눈이 나오는 경우에는 (그 중 가장 큰 눈)*100원의 상금을 받게 된다.  


#. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def check():
    for idx in range(3):
        if lst[idx] == lst[idx+1]:
            return idx
 
mmax, cost = -10
 
for i in range(int(input())):
    lst = sorted(list(map(int, input().split())))
 
    s = len(set(lst))
 
    if s == 1:
        cost = 50000 + lst[0* 5000
    elif s == 2:
        if lst[0== lst[1and lst[2== lst[3]:
            cost = 2000 + lst[0* 500 + lst[3* 500
        else:
            cost = 10000 + lst[1* 1000
    elif s == 3:
        cost = 1000 + lst[check()] * 100
    else:
        cost = lst[3* 100
 
    if cost > mmax:
        mmax = cost
 
print(mmax)
cs


#. Other Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def money():
    lst = sorted(list(map(int, input().split())))
    s = len(set(lst))
    if s == 1:
        return 50000 + lst[0* 5000
    elif s == 2:
        if lst[1== lst[2]:
            return 10000 + lst[1* 1000
        else:
            return 2000 + lst[0* 500 + lst[3* 500
    for i in range(3):
        if lst[i] == lst[i+1]:
            return 1000 + lst[i] * 100
    return lst[-1* 100
 
= int(input())
 
print(max(money() for i in range(N)))
cs


역시나.. 더 간결하게 짜셨다


line 1~14) 확실히 함수로 구현하는게 훨씬 가독성도 좋고 간결한 것 같다.

line 7) 여기서 lst[1]과 lst[2]만 비교해줘도 됐었는데.. 

line 18) 이게 가능한지 몰랐다..ㅋㅋㅋ


반응형
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday