728x90
알파벳 개수 찾는 문제와 거의 동일하다.
리스트를 -1로 초기화하고 해당 알파벳의 인덱스에 입력받은 알파벳의 인덱스 값을 넣어주면 된다.
코드
import sys
alphabet =[-1] * 26
str = sys.stdin.readline().rstrip()
for i in range(len(str)):
if(alphabet[ord(str[i]) - 97] == -1 ):
alphabet[ord(str[i]) - 97] = i
print(*alphabet)
입출력
'Algorithm' 카테고리의 다른 글
[알고리즘] 단어 길이 재기 백준 2743 (Python) (0) | 2022.01.17 |
---|---|
[알고리즘] 문자열 분석 백준 10820 (Python) (0) | 2022.01.17 |
[알고리즘] 알파벳 개수 백준 10808 (Python) (0) | 2022.01.17 |
[알고리즘] 덱 백준 10866 (Python) (0) | 2022.01.16 |
[알고리즘] 큐 백준 10845 (Python) (0) | 2022.01.14 |