일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- programmers
- 재귀함수
- 동적 계획법
- 정렬
- 카카오
- lambda
- dfs
- DateTime
- heapq
- 추석맞이 코딩챌린지
- Re
- 위클리 챌린지
- 그리디
- Combinations
- 백준
- 이분탐색
- KAKAO BLIND RECRUITMENT
- backjoon
- 수학
- 프로그래머스
- 파이썬
- BFS
- Zip
- 정규식
- 다익스트라
- python
- 자바
- java
- divmod
- Set
Archives
- Today
- Total
상상쓰
[백준] 단어 수학 본문
https://www.acmicpc.net/problem/1339
1339번: 단어 수학
첫째 줄에 단어의 개수 N(1 ≤ N ≤ 10)이 주어진다. 둘째 줄부터 N개의 줄에 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 대문자로만 이루어져있다. 모든 단어에 포함되어 있는 알파벳은 최대
www.acmicpc.net
주어진 단어에 index 마다 가중치를 부여한다. 같은 index 라도 중복이 일어날 때는 같은 index 의 다른 알파벳보다 가중치를 크게 줘야 하므로 index 의 초기 가중치를 10 ** j 로 한다.
import sys
from collections import defaultdict
N = int(sys.stdin.readline())
dic = defaultdict(int)
array = []
for i in range(N):
s = sys.stdin.readline().strip()
array.append(s)
s = s[::-1]
for j in range(0, len(s)):
dic[s[j]] = dic[s[j]] + (10 ** j)
c = 9
answer = 0
for key, value in sorted(dic.items(), key = lambda x : -x[1]):
dic[key] = c
c = c - 1
for i in array:
string = ''
for j in i:
string = string + str(dic[j])
answer = answer + int(string)
print(answer)
'Coding Test' 카테고리의 다른 글
[프로그래머스] 경주로 건설 (0) | 2021.06.07 |
---|---|
[프로그래머스] 보석 쇼핑 (0) | 2021.06.07 |
[백준] 신입 사원 (0) | 2021.06.06 |
[백준] 잃어버린 괄호 (0) | 2021.06.05 |
[프로그래머스] 기둥과 보 설치 (0) | 2021.06.04 |