전체 글 177

[Python][SWEA] 1859. 백만 장자 프로젝트 D2

🗒️ 파이썬 코드 풀이T = int(input())for tc in range(1,T+1): N = int(input()) lst = list(map(int,input().split())) u_lst = lst[::-1] max = u_lst[0] ans = 0 for i in range(1,len(u_lst)): if u_lst[i] > max : max = u_lst[i] else : ans += (max-u_lst[i]) print(f"#{tc} {ans}") 1.(문제점)0 인덱스에서 순차적으로 하면, 최대값이 계속 갱신될 수 있다는 생각을 하게된다.최대값이 갱신되면, 과거의 최대값은 무용지물이 ..

[Python][SWEA] 10580. 전봇대 D3

🗒️ 파이썬 코드 풀이from itertools import combinationsT = int(input())for tc in range(1, T+1): N = int(input()) lst = [list(map(int,input().split())) for _ in range(N)] connection = 0 combi = list(combinations(lst,2)) for c in combi: if c[0][0] > c[1][0] and c[0][1] c[1][1] : connection += 1 print(f"#{tc} {connection}") 1. (a1,b1) 과 (a2,b2) 이렇게 전선의 위치가 있을때 a1 2. itertools를 사용해..

[Python][SWEA] 3809. 화섭이의 정수 나열 D3

🗒️ 파이썬 코드 풀이T = int(input())for tc in range(1, T+1): N = int(input()) value = "" while True : value += ''.join(list(input().split())) if len(value) == N : break n = 0 while True: if str(n) not in value: break n += 1 print(f"#{tc} {n}") 1. 우선 입력구조가 다른 문제와 다르다. (10개의 입력이 넘어가면 엔터가 있음)이런 경우  반복문을 돌려서 해당값을 받아줘야한다.  N의 개수를 입력 받기 때문에,  value의 크기..

[Python][프로그래머스] 최대공약수와 최소공배수

🗒️ 파이썬 코드 풀이def gcd(n,m): # 최대공약수 if m==0: return n return gcd(m,n%m)def lcm(n,m) : # 최소공배수 return (n*m)//gcd(n,m)def solution(n, m): gc = gcd(n,m) lc = lcm(n,m) return [gc,lc] 1. 먼저 최대공약수를 재귀함수를 이용해서 구해준다.  2. 이후 최소공배수를 최대공약수를 이용해서 구해준다. 🧐 문제 코멘트문제가 어렵지는 않는데, 최대공약수와 최소공배수의 값을 구하는 방식을 꼭 기억하자막상 문제 풀때 생각 안나면 멘탈이 깨질듯 ...📚 문제문제 설명두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수,..

[Python][SWEA] 4698. 테네스의 특별한 소수 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️ 파이썬 코드 풀이lst = [i for i in range(1000001)] # 에라토스테네스 리스트 만들기for i in range(2,1000001) : # 2부터 시작해야 함 for j in range(i,1000001,i): # 각 수의 배수를 0으로 변환 if lst[j] == i : continue # i=j (해당값)은 변환 X lst[j] = 0T = int(input())for test_case in range(1, T + 1): D,A,B = map(int,input().split()) cnt = 0 ..

[Python][SWEA] 4751. 다솔이의 다이아몬드 장식 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️ 파이썬 코드 풀이T = int(input())for tc in range(1,T+1): dasol = list(input()) lst = [["."] * 5 for _ in range(5)] # 다이아 몬드 형태로 바꿔주기 shap = [(0,2),(1,1),(1,3),(2,0),(2,4),(3,1),(3,3),(4,2)] for i,j in shap: lst[i][j] = "#" chaged_lst = [lst[i].copy() for i in range(5)] # 얕은 복사 # 기존 리스트 변형 (맨 뒤 요..

[Python][SWEA] 9480. 민정이와 광직이의 알파벳 공부 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️ 파이썬 코드 풀이def Alphabet_combination(n,lst_union): global ans if n == N : if lst_union == alphabet: ans+=1 return Alphabet_combination(n+1,lst_union|set(lst[n])) Alphabet_combination(n+1,lst_union)T = int(input())for tc in range(1,T+1): N = int(input()) lst = [set(input().str..

[Python][SWEA] 14413. 격자판 칠하기 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️ 파이썬 코드 풀이def grid(type1,type2) : for i in range(N): for j in range(M) : if lst[i][j] == '?' : continue # "?"인 값은 제외 if (i+j)%2 == 0 : # i+j가 짝수인 경우 if lst[i][j] != type1: # 각 case와 일치하지 않는 경우 return False else : if lst[i][j]..

[Python][SWEA] 6485. 삼성시의 버스 노선 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️ 파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N = int(input()) lst = [0]*5001 for _ in range(N) : A,B = map(int,input().split()) for i in range(A,B+1) : lst[i] += 1 ans = [] P = int(input()) for _ in range(P) : P_num = int(input()) ans.append(lst[P_num]) ..

[Python][SWEA] 7510. 상원이의 연속 합 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️ 파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N = int(input()) cnt = 1 sum = 0 i = 2 # 연속이 되기 위한 최소 수 while True : sum += i-1 if (N-sum)  1. 해당 규칙이 있는데, 이 규칙을 코드로 풀면 된다.2개 연속  :  n + (n+1) = N   => (N-1) / 2 = n3개 연속  :  n + (n+1) + (n+2) = N    => (N - (1+2)) / 3 = n4개 연속  :  n + ..