C++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int arr[26];
fill(arr, arr + 26, -1);
string str;
cin >> str;
for (int idx = 0; idx < str.length(); idx++) {
if (arr[str.at(idx) - 'a'] == -1)
arr[str.at(idx) - 'a'] = idx;
}
for (int idx = 0; idx < 26; idx++)
cout << arr[idx] << " ";
return 0;
}
Python)
import sys
read = sys.stdin.readline
temp = read().rstrip()
arr = [-1] * 26
for idx, ch in enumerate(temp):
if arr[ord(ch)-ord('a')] == -1:
arr[ord(ch)-ord('a')] = idx
print(' '.join(map(str, arr)))'백준 1 > 기초' 카테고리의 다른 글
| [백준 2675] 문자열 반복 (C++/Python) (0) | 2020.12.05 |
|---|---|
| [백준 1152] 단어의 개수 (C++/Python) (0) | 2020.12.05 |
| [백준 8958] OX 퀴즈 (C++/Python) (0) | 2020.12.05 |
| [백준 10818] 최소, 최대 (C++/Python) (0) | 2020.12.05 |
| [백준 11721] 열 개씩 끊어 출력하기 (C++/Python) (0) | 2020.12.05 |