알고리즘 40

python snake game (20230612 coding test)

import random print('10점을 얻거나 벽에 닿으면 종료됩니다.') print('1:위 2:아래 3:오른쪽 4:왼쪽') print('0:빈곳 1:먹이 2:나') weight = int(input('게임장의 넓이:')) height = int(input('게임장의 높이:')) board = [[0 for j in range(0, weight)] for i in range(0, height)] score = 0 #나 처음위치 a = 0 b = 0 board[a][b] = 2 #먹이 food_height = 0 food_weight = 0 def set_food(): #먹이위치 랜덤 global food_height, food_weight food_height = random.randrange(..

백준 3052 python

resultArr = [] finalArr = [] for _ in range(10): incomeInt = int(input()) % 42 resultArr.append(incomeInt) # 그냥 함수 1줄이면 됩니다. # 순서 있으면 list(dict.fromkeys(array)) 없으면 list(set(array)) # finalArr = list(dict.fromkeys(resultArr)) for x in resultArr: if x not in finalArr: finalArr.append(x) print(len(finalArr)) 주석에도 적었는데 그냥 함수 1줄이면 됩니다.(for문을 돌리지 마세요) 저는 인터넷을 안 찾아봤을 경우를 가정한 것입니다.(솔직히 이런 경우는 없지만...)

백준 5597 python

이 코드는 실패한 코드입니다.(채점에서 틀리다고 나옵니다.) 맨 아래에 정답이 있습니다. studentList = [] for i in range(0, 28): studentList.insert(i,int(input())) sortList = sorted(studentList) for x in range(0,len(sortList)): y = x - 1 if x != 0: if sortList[y] != sortList[x] - 1: print(sortList[y] + 1) 알고리즘을 개인적으로 실행할 때는 결과가 잘 나왔습니다. 하지만 백준에서는 정답이 아니라고 나옵니다. 다른 분들은 remove함수를 사용합니다. 저도 이 방식보다는 remove방식을 추천드립니다. https://claude-u.tis..