Study hard
(c++)백준 10809번: 알파벳 찾기 본문
https://www.acmicpc.net/problem/10809
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
[풀이]
C++ STL string에 정의된 함수 find_first_of를 사용하여 풀 수 있다.
값을 찾지 못할 경우 npos(default: -1)가 저장되므로 따로 -1을 저장하는 과정이 필요 없다.
#include <iostream>
#include <string>
using namespace std;
string S;
int Alphabet[26];
void solution() {
cin >> S;
for (int i = 0; i < 26; i++) {
char alpha = char(i + 'a');
Alphabet[i] = S.find_first_of(alpha);
}
for (int i = 0; i < 26; i++) {
cout << Alphabet[i] << ' ';
}
}
int main() {
solution();
return 0;
}
'백준 > 여러가지 문제들' 카테고리의 다른 글
(c++)백준 11655번: ROT13 (0) | 2020.06.13 |
---|---|
(c++)백준 10820번: 문자열 분석 (0) | 2020.06.12 |
(c++)백준 10808번: 알파벳 개수 (0) | 2020.06.12 |
(c++)백준 10866번: 덱 (0) | 2020.06.12 |
(c++)백준 10845번: 큐 (0) | 2020.06.12 |