[PS 백준 - 1.4] 10809번: 알파벳 찾기

PongkiJoa·2021년 6월 29일
0

PS Diary - 백준

목록 보기
5/54
post-thumbnail

문제 정보

백준 10809번 - 바로가기

  • 난이도: 브론즈 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 << ' ';
	}
}
profile
컴공 20학번

0개의 댓글

관련 채용 정보