Study hard
(c++)백준 10808번: 알파벳 개수 본문
https://www.acmicpc.net/problem/10808
10808번: 알파벳 개수
단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.
www.acmicpc.net
[풀이]
int형 배열에 해당 알파벳이 나올때마다 해당 알파벳 - 'a' 번째 index 자리에 +1 해준다.
#include <iostream>
#include <string>
using namespace std;
string S;
int Alphabet[26];
void solution() {
cin >> S;
for (int i = 0; i < S.size(); i++) {
int index = S[i] - 'a';
Alphabet[index] ++ ;
}
for (int i = 0; i < 26; i++) {
cout << Alphabet[i] << ' ';
}
}
int main() {
solution();
return 0;
}
'백준 > 여러가지 문제들' 카테고리의 다른 글
(c++)백준 10820번: 문자열 분석 (0) | 2020.06.12 |
---|---|
(c++)백준 10809번: 알파벳 찾기 (0) | 2020.06.12 |
(c++)백준 10866번: 덱 (0) | 2020.06.12 |
(c++)백준 10845번: 큐 (0) | 2020.06.12 |
(c++)백준 10799번: 쇠막대기 (0) | 2020.06.12 |