- 난이도: 브론즈 2
- 알고리즘: 문자열
알파벳을 인덱스로 사용할 때 str.at(i) - 'a' 로 접근한 것이 포인트였다.
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(NULL);
cout.tie(NULL);
std::ios::sync_with_stdio(false);
string str;
cin >> str;
// 26칸을 -1로 채운 벡터
vector<int> vec(26, -1);
for (int i = 0; i < str.length(); i++) {
if (vec[str.at(i) - 'a'] == -1)
vec[str.at(i) - 'a'] = i;
}
for (auto it = vec.begin(); it != vec.end(); it++) {
cout << *it << ' ';
}
}