본문 바로가기
Algorithm

[알고리즘] 알파벳 찾기 백준 10809 (Python)

by 가영리 2022. 1. 17.
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)

 

입출력