Programming 기초
-
[이코테] 모험가 길드,럭키 스트레이트Programming 기초/Coding Test 2023. 8. 18. 18:20
*그리디 # 1회차 시도 # 시간 초과 n=int(input()) arr=list(map(int,input().split())) arr.sort() count=0 visited=[False]*n for i, num in enumerate(arr): if i+num = max(arr[i:i+num]): for j in range(i,i+num): visited[j]=True count+=1 print(count) *구현 #1회차 -> 더 안 해도 될 듯 n=list(map(int,input())) m=len(n)//2 if sum(n[:m])==sum(n[m:]): print('LUCKY') else : print('READY')
-
[Python] return self는 method chaining을 위함이다.Programming 기초/Python 2023. 8. 5. 00:04
* 클래스 내의 메서드(Method)에서 return self를 하는 이유 메서드 체이닝(Chaining)과 메서드 호출의 연속적인 처리를 용이하게 하기 위함이다. 메서드 체이닝은 한 줄의 코드에서 여러 메서드를 연속적으로 호출하는 기법을 의미한다. 예를 들어, obj.method1().method2().method3()와 같이 객체 obj의 메서드들을 연속해서 호출하는 것을 말한다. 이때 메서드는 각각 self를 반환해야만 메서드 체이닝이 가능해진다. 메서드가 return self를 반환하면 해당 메서드는 자기 자신의 인스턴스를 반환한다. 따라서 다른 메서드를 호출할 때에도 동일한 객체에 대해 메서드를 연속해서 호출할 수 있게 된다. 이는 코드를 간결하고 가독성이 높게 만들어준다. 예를 들어, 다음은 ..
-
[이코테#다이나믹 프로그래밍] 1로 만들기(DP문제 기본 유형)Programming 기초/Coding Test 2023. 7. 30. 20:23
* 1로 만들기 정수 X가 주어질 때 정수 X에 사용할 수 있는 연산은 다음과 같이 4가지이다. ㄱ. X가 5로 나누어떨어지면 5로 나눈다. ㄴ. X가 3으로 나누어떨어지면 3으로 나눈다. ㄷ. X가 2로 나누어떨어지면, 2로 나눈다. ㄹ. X에서 1을 뺀다. 네 가지 연산을 사용하여 1을 만들 때, 연산을 사용하는 횟수의 최솟값을 출력하라. 입력 : 1 불가 8을 2로 나눈다 -> 4 4을 5로 나눈다 -> 불가 4을 3로 나눈다 -> 불가 4을 2로 나눈다 -> 2 2의 연산 최소횟수는 1 4에서 1을 뺀다 -> 3 3의 연산 최소횟수는 1 8에서 1을 뺀다 -> 7 7을 5로 나눈다 -> 불가 7을 3로 나눈다 -> 불가 7을 2로 나눈다 -> 불가 7에서 1을 뺀다 -> 6 6을 5로 나눈다 ->..
-
[python#tip] PEP8- code styleProgramming 기초/Python 2023. 7. 26. 23:50
네이버 부스트코스 코칭스터디 12기 에 리드부스터로 참여하고 있다. 팀원들과 매주 미션을 해결하면서 받았던 코치님의 피드백 중에 PEP8이라는 코드 스타일을 연습해볼 것을 추천해주셨다. 해서, PEP8을 공부하고 여기에 정리하고자 한다. 아래 노션에 나머지 부분을 정리했다. https://mud-gorilla-c43.notion.site/PEP8-bcae91a5d0b54b9892e1ab21a891512a?pvs=4 PEP8 🟧 Prescriptive: Naming Conventions(교시적: 네이밍 규칙.) mud-gorilla-c43.notion.site *PEP8 대부분의 경우 실무에서는 팀 프로젝트로 진행된다. 그렇기에 코드를 작성할 때 약속이 정해져있으면 가독성을 높이고 효율을 높일 수 있다(유..
-
[BOJ#1316] sorted(s,key=s.find), generator, iterable, iterator 개념Programming 기초/Coding Test 2023. 7. 19. 02:45
* 그룹 단어 체커(1316번) 더보기 그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때문에 그룹 단어이지만, aabbbccb는 b가 떨어져서 나타나기 때문에 그룹 단어가 아니다. 단어 N개를 입력으로 받아 그룹 단어의 개수를 출력하는 프로그램을 작성하시오. 첫째 줄에 단어의 개수 N이 들어온다. N은 100보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 단어가 들어온다. 단어는 알파벳 소문자로만 되어있고 중복되지 않으며, 길이는 최대 100이다. 첫째 줄에 그룹 단어의 개수를 출력한다. # 내 답변 # 연속해서 중복되는 글자들..
-
[BOJ#2444번] range의 역순 : range(n,0,-1), range(n)[::-1]Programming 기초/Coding Test 2023. 7. 12. 08:54
* 별 찍기(2444번) 더보기 문제 예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요. * *** ***** ******* ********* ******* ***** *** * 입력 첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다. 출력 첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다. # 내 풀이 n = int(input()) arr = ["*" * (2 * i - 1) for i in range(1, n + 1)] for i in range(n): print(" " * (n - i - 1) + arr[i]) for i in range(n - 1)[::-1]: print(" " * (n - i - 1) + arr[i]) # 다른 답변 n = int(input()) for i in range(..
-
[BOJ#3003번] list(zip()), 두 리스트의 원소를 순서대로 짝을 맞춰 엮는 방법Programming 기초/Coding Test 2023. 7. 11. 11:03
* 킹, 퀸, 룩, 비숍, 나이트, 폰 (3003번) 더보기 문제 동혁이는 오래된 창고를 뒤지다가 낡은 체스판과 피스를 발견했다. 체스판의 먼지를 털어내고 걸레로 닦으니 그럭저럭 쓸만한 체스판이 되었다. 하지만, 검정색 피스는 모두 있었으나, 흰색 피스는 개수가 올바르지 않았다. 체스는 총 16개의 피스를 사용하며, 킹 1개, 퀸 1개, 룩 2개, 비숍 2개, 나이트 2개, 폰 8개로 구성되어 있다. 동혁이가 발견한 흰색 피스의 개수가 주어졌을 때, 몇 개를 더하거나 빼야 올바른 세트가 되는지 구하는 프로그램을 작성하시오. 입력 첫째 줄에 동혁이가 찾은 흰색 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수가 주어진다. 이 값은 0보다 크거나 같고 10보다 작거나 같은 정수이다. 출력 첫째 줄에 입력에서 주어진..