-
Notifications
You must be signed in to change notification settings - Fork 2
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
33-Dolchae #124
33-Dolchae #124
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,32 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n = int(input().strip()) | ||
serial = [] | ||
|
||
for _ in range(n): | ||
serial.append(input().strip()) | ||
|
||
def get_number_sum(s): | ||
number_sum = 0 | ||
for char in s: | ||
if char.isdigit(): | ||
number_sum += int(char) | ||
return number_sum | ||
Comment on lines
+10
to
+15
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. def get_number_sum(s):
return sum(int(char) for char in s if char.isdigit()) ์๋ ๊ฒ ํ ์ค๋ก ๊ฐ๋จํ๊ฒ ์ค์ผ ์ ์๋ต๋๋ค :) |
||
|
||
for i in range(n-1): | ||
for j in range(i+1, n): | ||
if len(serial[i]) > len(serial[j]): | ||
serial[j], serial[i] = serial[i], serial[j] | ||
elif len(serial[i]) == len(serial[j]): | ||
i_total = get_number_sum(serial[i]) | ||
j_total = get_number_sum(serial[j]) | ||
if i_total > j_total: | ||
serial[j], serial[i] = serial[i], serial[j] | ||
elif i_total == j_total: | ||
if serial[i] > serial[j]: | ||
serial[j], serial[i] = serial[i], serial[j] | ||
Comment on lines
+17
to
+28
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. ํ์ด์ฌ์ sort๋ ๊ฐ๋ ฅํฉ๋๋ค. ์ ๋ ฌ ๊ธฐ์ค์ธ key๋ฅผ ์ ์ ํด์ฃผ๊ธฐ๋ง ํ๋ฉด ๋๋๊น์. ์ด ๋ฌธ์ ์ ๊ฒฝ์ฐ 1. ๊ธธ์ด๊ฐ ์งง์ ์ 2. ์๋ฆฟ์ ํฉ์ด ์ ์ ์ 3. ์ฌ์ ์ ์ฐ์ ์์๋ก ์ ๋ ฌํด์ผ ํ์์์? ๊ทธ๋ฌ๋๊น serial.sort(key=lambda x: (len(x), get_number_sum(x), x)) ์ด๋ ๊ฒ ๋๋ค๋ก ์ ํด์ฃผ๋ฉด ๋ฉ๋๋ค. x๊ฐ ๊ฐ๊ฐ์ ์์์ธ ๋ฌธ์์ด์ ์๋ฏธํ๋ฏ๋ก
์ ๋ ฌํ๊ฒ ๋ฉ๋๋ค :) |
||
|
||
for i in serial: | ||
print(i) | ||
|
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.
๋ ๋ง ํ๋ ๊ฒ์ด์ง๋ง,
์ผ๋ก ์ค์ฌ์ธ ์ ์๊ฒ ์ฃ ?