[BOJ]10809:アルファベット検索



🔒 例

>> baekjoon

1 0 -1 -1 2 -1 -1 -1 -1 4 3 -1 -1 7 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

🔧 に答える

1. wrd = sys.stdin.readline().rstrip()
2. alpha = ['-1' for i in range(26)] : 출력형식 고려하여 수정
3. alpha[idx] = i : 'a' == 0, 'b' == 1, ..., 'z' == 25 

🔑 答案用紙

import sys

wrd = sys.stdin.readline().rstrip()
alpha = ['-1' for i in range(26)]

for i in range(len(wrd)):
	idx = ord(wrd[i])- ord('a')
	if alpha[idx] == '-1':
		alpha[idx] = str(i)

print(" ". join(alpha))

💡 コンセプト

### join : list to string 
colors = ['red', 'yellow' 'orange', 'green', 'blue']
print(':'.join(colors)) # red:yellow:orange:green:blue
print('//'.join(colors)) # red//yellow//orange//green//blue

### ord: char to ascii value <class 'int'>
ord('a')	# 97
ord('1')	# 49

### chr: ascii value to char <class 'str'>
chr(97)		# a
chr(49)		# 1