-
[백준] 1431번 시리얼번호(python)Python/BAEKJOON 2022. 2. 15. 18:47728x90
문제)
알고리즘)
- 정렬 람다(lambda) 함수 활용 조건 우선순위
1. 길이 2. 숫자총합 3. 알파벳 사전순
- def f(a) 함수 i.isdigit() 함수 사용
isdigit => 문자열내에 숫자가 있다면 T/F 반환
각 문자열의 숫자가 있다면 result에 숫자변환 후 더한 후 result 출력
람다 정렬 후 최종출력
코드)
#시리얼 번호 import sys input = sys.stdin.readline n = int(input()) data = [input().rstrip() for _ in range(n)] def f(a): result = 0 for i in a: if i.isdigit(): #숫자가 있다면? result += int(i) return result data.sort(key=lambda x:(len(x), f(x), x)) #조건(길이, 숫자총합, 알파벳) for x in data: print(x)
728x90'Python > BAEKJOON' 카테고리의 다른 글
[백준] 2304번 창고 다각형(python) (0) 2022.02.22 [백준] 3036번 링(python) (0) 2022.02.15 [백준] 1260번 DFS와 BFS(python) (0) 2022.01.29 [백준] 2606번 바이러스(python) (0) 2022.01.23 [백준] 8911번 거북이(python) (0) 2022.01.21