# 생각
key와 value가 있는 배열로 해결 가능하고
알파벳만 있으므로 a to z를 0 ~ 26까지 배열에 담아 카운트해줄 수 있다
# 전체 코드
#include <bits/stdc++.h>
using namespace std;
void fastIO() { ios::sync_with_stdio(false); cin.tie(nullptr); }
int h[9];
int main()
{
fastIO();
string s;
cin >> s;
int cnt[26] = {0,};
for (char& c : s)
{
cnt[c - 'a']++;
}
for (int i = 0; i < 26; i++)
{
cout << cnt[i] << ' ';
}
}
https://www.acmicpc.net/problem/10808
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 10988_팰린드롬인지 확인하기.cpp (0) | 2022.05.28 |
---|---|
[BOJ] 2979_트럭 주차.cpp (0) | 2022.05.28 |
[BOJ] 2309_일곱 난쟁이.cpp (0) | 2022.05.28 |
[BOJ] 2146_다리 만들기 with cpp (0) | 2022.03.10 |
[BOJ] 14503_로봇 청소기 with cpp (0) | 2022.03.09 |