practivceAlgorithm/백준
[백준][Python] 19948 음유시인영재
findTheValue
2021. 10. 18. 02:51
시와 제목을 잇고 딕셔너리에 횟수를 저장, 1씩 빼주는 식. 다음꺼랑 문자 같으면 조사 x
import sys
input = sys.stdin.readline
poem = input().rstrip()
title = ''.join([a[0].upper() for a in poem.split()])
poem += title + '.'
left_space = int(input())
left_push_alphabet = {idx: cnt for idx, cnt in enumerate(map(int, input().split()))}
for i in range(len(poem) - 1):
if poem[i] == poem[i + 1]:
continue
if poem[i] == ' ':
if left_space:
left_space -= 1
else:
print(-1)
exit()
else:
if left_push_alphabet[ord(poem[i].lower()) - 97]:
left_push_alphabet[ord(poem[i].lower()) - 97] -= 1
else:
print(-1)
exit()
else:
print(title)