Max Consecutive Ones python class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: result = 0 a = [] for i in nums: if i == 1: result += 1 else: a.append(result) result = 0 a.append(result) return max(a) 1이 중복된 수를 리스트로 만들고 리스트중 최댓값 찾기 알고리즘/배열(array) 2023.06.26
백준 1546 python list_count = int(input()) score = list(map(int, input().split())) after_list = [] max_score = max(score) for i in score: after_scroe = float(i / max_score * 100) after_list.append(after_scroe) print(float(sum(after_list)) / list_count) 알고리즘/배열(array) 2023.06.13
백준 10811 python list_count, input_int = list(map(int, input().split())) bucket = [i for i in range(1,list_count + 1)] after_bucket = [] for _ in range(input_int): a, b = list(map(int, input().split())) after_bucket = list(reversed(bucket[a-1:b])) bucket[a-1:b] = after_bucket print(' '.join(str(e) for e in bucket)) 알고리즘/배열(array) 2023.06.13
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(.. 알고리즘/배열(array) 2023.06.12
백준 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문을 돌리지 마세요) 저는 인터넷을 안 찾아봤을 경우를 가정한 것입니다.(솔직히 이런 경우는 없지만...) 알고리즘/배열(array) 2023.06.11
백준 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.. 알고리즘/배열(array) 2023.06.11
백준 10813 python 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) 2023.06.10
백준 10810 python listCount, comInt = list(map(int, input().split())) bucket = [0] * listCount for x in range(comInt): bList = list(map(int, input().split())) for y in range(bList[0]-1,bList[1]): bucket[y] = bList[2] print(' '.join(str(e) for e in bucket)) 알고리즘/배열(array) 2023.06.09
백준 2562 python intList = [] for x in range(9): insertInt = int(input()) intList.insert(x, insertInt) print(max(intList)) print(intList.index(max(intList))+1) 알고리즘/배열(array) 2023.06.09
백준 10818 python lenList = int(input()) intList = list(map(int, input().split())) sortedList = sorted(intList) indexOfBIg = lenList - 1 print(sortedList[0], sortedList[indexOfBIg]) 부족한 부분은 댓글로 알려주시면 감사한 마음으로 수정하겠습니다. 알고리즘/배열(array) 2023.06.09