BOJ

Baekjoon #10809번 알파벳찾기 Python

Edan Cafe ☕ 2020. 10. 5. 11:49

 

1
2
3
4
5
6
= input()
result = [-1]*26
for i in range(len(s)):
    if result[ord(s[i])-97== -1:
        result[ord(s[i])-97= i
print(result)
cs

생소한 문제라 조금 어려웠습니다.

=========================================

문제점이 생겼습니다.

result는 리스트로 출력되는데 채점현황에는 틀렸습니다. 로 채점이 됩니다.

문제점이 뭘까 고민하다가 찾은 결론은 // 백준에서 원하는 답은 문자열로 반환하길 원합니다.

따라서 소스를 조금 수정하였습니다.

1
2
3
4
5
6
7
8
9
10
11
12
= input()
string_result = ''
result = [-1]*26
for i in range(len(s)):
    if result[ord(s[i])-97== -1:
        result[ord(s[i])-97= i
 
for j in result:
    j = str(j)
    string_result = string_result + j + " "
 
print(string_result)

결과///

잘 나옵니다

반응형