euisblue
10808. 알파벳 개수

10808 - 알파벳 개수

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

C++

1#include <bits/stdc++.h> 2using namespace std; 3 4int main(void) { 5 int alphabet[26] = {0}; 6 string s; 7 cin >> s; 8 9 // O(n), n = length of 's' 10 for(char c : s) ++alphabet[c - 'a']; 11 12 for(int i=0; i<26; ++i) 13 printf("%d ", alphabet[i]); 14 15 return 0; 16}