반응형
https://www.acmicpc.net/problem/10809
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
정답 코드 1
s = list(input())
alphabet = []
for i in range(26):
alphabet.append(-1)
for i in range(len(s)):
index = ord(s[i]) - 97
if (alphabet[index] == -1):
alphabet[index] = i
for i in range(len(alphabet)):
print(alphabet[i], end=' ')
정답 코드 2
s = input()
alphabet = []
for i in range(26):
alphabet.append(-1)
count = 0
for i in s:
index = ord(i) - 97
if (alphabet[index] == -1):
alphabet[index] = count
count += 1
print(*alphabet, sep=" ")
반응형
'algorithm > Baekjoon' 카테고리의 다른 글
[python] 백준 1157_단어 공부 (0) | 2021.08.04 |
---|---|
[python] 백준 2675_문자열 반복 (0) | 2021.08.04 |
[c언어] 백준 2577_숫자의 개수 (0) | 2021.08.03 |
[python] 백준 11720_숫자의 합 (0) | 2021.07.27 |
[python] 백준 11654_아스키코드 (0) | 2021.07.27 |