알고리즘/배열(array)

백준 10813 python

자코린이 2023. 6. 10. 00:10
listCount, comInt = list(map(int, input().split()))

bucket = [0] * listCount
for i in range( listCount):
    bucket[i] = (i + 1)
    
print(bucket)

for x in range(comInt):
    index1, index2 = list(map(int, input().split()))
    index11 = index1 - 1
    index12 = index2 - 1
    a = bucket[index11]
    b = bucket[index12]
    bucket[index12] = a
    bucket[index11] = b
    print(bucket)
    
print(' '.join(str(e) for e in bucket))

제가 짠 코드긴 하지만 보완할 부분이 많습니다.

다른 분들이 만든 코드도 참고하세요.

'알고리즘 > 배열(array)' 카테고리의 다른 글

백준 3052 python  (0) 2023.06.11
백준 5597 python  (0) 2023.06.11
백준 10810 python  (0) 2023.06.09
백준 2562 python  (0) 2023.06.09
백준 10818 python  (0) 2023.06.09