Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 백준
- 그래프탐색
- 그리디알고리즘
- 다이나믹프로그래밍
- 자료구조
- BOJ
- swift
- 백준알고리즘
- 너비우선탐색
- 두 포인터
- 구현
- 브루트포스 알고리즘
- 해시를사용한집합과맵
- 프로그래머스
- Xcode
- 파이썬
- 누적 합
- 정렬
- programmers
- 알고리즘
- python3
- Mac
- 문자열
- 그래프이론
- 큐
- 코딩테스트
- 스택
- 트리를사용한집합과맵
- 깊이우선탐색
- Python
Archives
- Today
- Total
Coding Cantabile
[Programmers] 개인정보 수집 유효기간(Python3, 파이썬) 본문
본 게시글은 프로그래머스 코딩테스트 연습 문제를 '파이썬, Python3' 언어로 풀이한 내용을 주관적으로 정리하였으며, 내용과 관련된 코드리뷰 및 피드백 환영합니다.
레벨
Level 1
문제 출처
https://school.programmers.co.kr/learn/courses/30/lessons/150370
내 풀이
def time_convert(t) :
year, month, day = map(int, t.split('.'))
return year * 12 * 28 + month * 28 + day
def solution(today, terms, privacies):
term_dict = dict()
today = time_convert(today)
answer = []
for term in terms :
name, period = term.split()
term_dict[name] = int(period) * 28
for idx, privacy in enumerate(privacies) :
start, name = privacy.split()
end = time_convert(start) + term_dict[name]
if end <= today :
answer.append(idx + 1)
return answer
문제 자체는 어렵지 않은 구현 문제였다. 다만 여기서 주어진 변수를 어떻게 활용할 것인가가 조금 관건이었다.
활용한 Python 문법
먼저 split()을 통해서 문자가 두 가지로 분리되었을 때, 아래와 같이 변수로 각각 저장할 수 있다.
test = ['2023.05.27 B']
day, name = test.split() # day = '2023.05.27', name = 'B'
또한 enumerate() 함수를 사용해서 인덱스도 함께 뽑아낼 수 있다.
for idx, privacy in enumerate(privacies) :
start, name = privacy.split()
# start = [0, 1, 2 ... ]
# name = ["2021.05.02 A", "2021.07.01 B", "2022.02.19 C"]'Coding Test > Programmers' 카테고리의 다른 글
| [Programmers] K번째 수(Python3, 파이썬) (0) | 2023.06.03 |
|---|---|
| [Programmers] 문자열 내 마음대로 정렬하기(Python3, 파이썬) (0) | 2023.06.03 |
| [Programmers] 최소직사각형(Python3, 파이썬) (1) | 2023.05.17 |
| [Programmers] 삼총사(Python3, 파이썬) (0) | 2023.05.17 |
| [Programmers] 푸드 파이트 대회(Python3, 파이썬) (0) | 2023.03.25 |