-
Notifications
You must be signed in to change notification settings - Fork 5
[여름방학 2주차] - 허원일 #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "2\uC8FC\uCC28/\uD5C8\uC6D0\uC77C"
[여름방학 2주차] - 허원일 #59
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)) | ||
| 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()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 함수별로 기능을 나눠둔게, 가독성이 좋게 느껴집니다 추가 견해
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 다른 스터디원들 풀이보고 아차 싶었는데 정확히 짚어 주셨네요ㅎㅎ 파이썬 기본문법 참고서 다시 펼쳐봐야겠씁니다.. |
||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python 쓰시는 분들은
set이랑slicing을 많이 사용하시는군요!