본문 바로가기
Study (etc)/Problem Solving

[BOJ / C++] 10808번 : 알파벳 개수

by Haren 2022. 4. 1.

문제

알파벳 소문자로만 이루어진 단어 S가 주어진다. 각 알파벳이 단어에 몇 개가 포함되어 있는지 구하는 프로그램을 작성하시오.

입력

첫째 줄에 단어 S가 주어진다. 단어의 길이는 100을 넘지 않으며, 알파벳 소문자로만 이루어져 있다.

출력

단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.

Solved.ac 레벨

브론즈 II

풀이

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string sAlphabet = "abcdefghijklmnopqrstuvwxyz";
    vector<int> vCnt;
    string sStr;
    cin >> sStr;

    for(int i = 0; i < sAlphabet.length(); i++){
        int nCnt = 0;
        for(int j = 0; j < sStr.length(); j++){
            if(sAlphabet[i] == sStr[j]){ 
                nCnt++;
            }
        }
        cout << nCnt << " ";
    }
    return 0; 
}

https://acmicpc.net/problem/10808