티스토리 뷰

백준

백준 2920 문제풀이 [python]

ys.k 2023. 6. 9. 03:40

포스팅에 앞서 내용이 틀릴 수 있습니다.
해당 부분 지적 감사히 받습니다.

문제를 보자.

솔직히 문제 푸는데 어렵지 않았다.

 

하지만 정말 이렇게 푸는 방법밖에 없나 라는 생각이 계속 들었다.

 

코드를 보자


array = list(map(int,input().split()))

if array[0] == 1:
    for i in range(0,8):
        if array[i] != i+1:
            print('mixed')
            break
    else:
        print('ascending')
else :
    for i in range(0,8):
        if array[i] + i != 8 :
            print('mixed')
            break
    else:
        print('descending')

그냥.. 뭔가 알고리즘이 아니라 손으로 만든 것 같은 느낌이다.

 

그게 맞긴한데.. 그냥 나는 꺼림칙하다.

 

그래서 다른 사람 코드 찾아봤는데

 

알고리즘 6줄에 끝내버리셨다.

 

좀만 더 잘 생각해볼걸 하고 후회가 된다.

 

J_Remind 님 블로그 참고.

a = list(map(int, input().split()))
 
if a == sorted(a):
    print('ascending')
elif a == sorted(a, reverse=True):
    print('descending')
else:
    print('mixed')

출처 : https://j-remind.tistory.com/39

 

(파이썬) 백준 알고리즘 2920번

문제풀이 (Python) 123456789a = list(map(int, input().split())) if a == sorted(a): print('ascending')elif a == sorted(a, reverse=True): print('descending')else: print('mixed') Colored by Color Scriptercs키워드 (Keyword)sorted리스트를 정렬 (새

j-remind.tistory.com

배운 점

1. 일단 맞으면 된 거다.

2. 다른 사람 풀이를 보고 내꺼로 만들면 된다.

'백준' 카테고리의 다른 글

백준 2178 문제풀이 [python]  (2) 2023.06.10
백준 1149 문제풀이 [python]  (0) 2023.06.09
백준 1003 문제풀이 [python]  (0) 2023.06.09
백준 1978 문제풀이 [python]  (0) 2023.06.08
백준 9012 문제풀이 [python]  (0) 2023.06.08
댓글