No Rules Rules

알파벳 찾기 (feat. 백준, 10809번) 본문

생활/코테

알파벳 찾기 (feat. 백준, 10809번)

개발하는 완두콩 2022. 8. 11. 12:09
728x90
반응형

알파벳 찾기
https://www.acmicpc.net/problem/10809

 

10809번: 알파벳 찾기

각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	string str;
	int ans[26];
	fill(ans, ans + 26, -1);
	cin >> str;
	for (register int i = 0; i < str.size(); ++i)
		if (ans[str.at(i) - 'a'] == -1)
			ans[str.at(i) - 'a'] = i;
	for (register int i = 0; i < 26; ++i)
		cout << ans[i] << " ";
	return 0;
}
// *&)*@*
  1. 소문자 알파벳은 총 26개 입니다.
  2. 입력받은 문자열에서 각각의 (문자 - 'a') 의 배열 인덱스를 기록하는 방식으로 풀이하였습니다.
728x90
반응형
Comments