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 | 29 | 30 | 31 |
Tags
- Typescript
- SQL 고득점 KIT
- javascript
- level 3
- 문자열
- Lv. 3
- bfs
- C언어
- 스택
- 프로그래머스
- DP
- Java
- Stack
- Dynamic Programming
- Lv. 1
- 소프티어
- Python
- dfs
- 너비 우선 탐색
- 다이나믹프로그래밍
- group by
- 브루트포스
- programmers
- softeer
- Lv. 0
- Lv. 2
- level3
- 파이썬
- 타입스크립트
- 자바스크립트
Archives
- Today
- Total
몸과 마음이 건전한 SW 개발자
프로그래머스 Lv2 파일명 정렬 Python 본문
문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/17686
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
정답 코드
def solution(files):
answer = []
lenFiles = len(files)
newFiles = [[0 for _ in range(3)] for _ in range(lenFiles)]
for r in range(lenFiles):
file = files[r]
lenFile = len(file)
nowIndex = 0
HEAD = ""
NUMBER = ""
TAIL = ""
for f in range(nowIndex, lenFile):
tmp = file[f]
if tmp.isdigit():
nowIndex = f
break
HEAD += tmp
for s in range(nowIndex, lenFile):
tmp = file[s]
if tmp.isdigit():
NUMBER += tmp
if s == lenFile - 1:
nowIndex = s + 1
else:
nowIndex = s
break
TAIL = file[nowIndex:]
newFiles[r][0] = HEAD
newFiles[r][1] = NUMBER
newFiles[r][2] = TAIL
sortedNewFiles = sorted(newFiles, key=lambda x: (x[0].upper(), int(x[1])))
for sNF in sortedNewFiles:
answer.append(sNF[0] + sNF[1] + sNF[2])
return answer
풀이 방법
- 쉽게 말해서 머리, 숫자, 꼬리를 나눈다음에
- 정렬을 해준다. 근데 여기서 람다식의 upper라거나 int(x[1]) 이런거 사용해보면 된다.
느낀점
- 분명 더 좋은 방식이 있을거라 내가 풀 수 있는지 검증해본 문제다. 의외로 오래 걸려서 놀랐고 가볍게 보다가 문제를 잘 못 읽어서 틀릴 수 있기 때문에 주의해야 한다.
- 반복문을 계속 돌렸는데 브루트포스라고 봐도 되지 않나?
'알고리즘' 카테고리의 다른 글
프로그래머스 Lv2 튜플 Python (2) | 2023.12.11 |
---|---|
프로그래머스 Lv2 JadenCase 문자열 만들기 Python (0) | 2023.12.11 |
Softeer Level 3 강의실 배정 Python [반례 포함] (0) | 2023.12.07 |
Softeer Level 3 징검다리 Python (4) | 2023.12.07 |
프로그래머스 [Lv. 3] 불량 사용자 Python (0) | 2023.09.17 |