๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10808๋ฒˆ - ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

by dkswnkk 2021. 10. 23.
 

10808๋ฒˆ: ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” a์˜ ๊ฐœ์ˆ˜, b์˜ ๊ฐœ์ˆ˜, …, z์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net

#include <iostream>
#include <vector>

using namespace std;
vector<char>alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
vector<int>ans(alphabet.size());
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string s; cin >> s;
    for (int i = 0; i < s.length(); i++) {
        for (int j = 0; j < alphabet.size(); j++) {
            if (s[i] == alphabet[j]) ans[j]++;
        }
    }
    for (int i : ans) {
        cout << i << " ";
    }
}

๋Œ“๊ธ€