Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 허원일/11478 서로 다른 부분 문자열의 개수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
string = input()
set = set() # 부분 문자열을 담을 세트 자료형 선언
for slice_len in range(1, len(string)+1): # 이중 for 중 첫번째 for - 부분문자열의 길이 기준
for j in range(0, len(string)): # 두번째 for - 부분문자열의 시작 인덱스 기준
set.add(string[j:j+slice_len]) # 세트 자료형에 해당 문자열 추가 (세트에 없으면)

print(len(set))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python 쓰시는 분들은 set이랑 slicing 을 많이 사용하시는군요!

16 changes: 16 additions & 0 deletions 허원일/1225 이상한 곱셈.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def solution():
a, b = map(int,input().split())
slice_a = []
slice_b = []
slice(slice_a, a)
slice(slice_b, b)
ans = sum(slice_a) * sum(slice_b)
return ans

def slice(slice_list, num):
while num > 0:
n = num % 10
slice_list.append(n)
num //= 10

print(solution())
Copy link
Collaborator

@alirz-pixel alirz-pixel Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 함수별로 기능을 나눠둔게, 가독성이 좋게 느껴집니다

추가 견해
  1. 작성하신 slice 함수를 python 내장 함수를 이용해서 구현 가능합니다
  1. slice 함수대신 slice_sum 이라는 함수를 만들어서 각 자리수의 합을 리턴해주는 함수를 만드는 것도 나쁘지 않았을 거 같네요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 다른 스터디원들 풀이보고 아차 싶었는데 정확히 짚어 주셨네요ㅎㅎ 파이썬 기본문법 참고서 다시 펼쳐봐야겠씁니다..

18 changes: 18 additions & 0 deletions 허원일/lv.1 문자열 압축.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def solution(s):
result = len(s) # result를 s의 길이으로 초기화 (이후 min 함수를 통해 최솟값으로 갱신 위해)
for slice_len in range(1, len(s)+1):
compressed = "" # 압축된 문자열을 담을 compressed
count = 1 # 압축된 횟수를 나타내는 count
prev = s[0:slice_len]
for start in range(slice_len, len(s), slice_len):
cur = s[start:start+slice_len]
if prev == cur: # 이전 문자열과 같으면 압축된 횟수 증가
count += 1
else: # 다르면 compressed에 바로 붙임
compressed += str(count) + prev if count >= 2 else prev
prev = cur # prev를 cur로 초기화
count = 1 # count 초기화
compressed += str(count) + prev if count >= 2 else prev # 마지막 문자열 처리

result = min(result, len(compressed)) # 기존의 result값과 현재 압축된 문자열의 길이를 비교하여 result값 갱신
return result