Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

알파벳 개수 본문

Algorithm/Cases-Study

알파벳 개수

Xi_kor 2020. 5. 4. 13:31

문제

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

입력

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

출력

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

예제 입력 1

baekjoon

예제 출력 1

1 1 0 0 1 0 0 0 0 1 1 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0

 

------------------------------------------------------------------------------------------------------------------------------

 

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	char arr[150];
	int alphabet[30] = { 0, };
	cin >> arr;

	int length = strlen(arr);

	int j = 0;
	for (int a = 97; a <= 122; a++) {
		for (int i = 0; i < length; i++) {
			if (arr[i] == a)
				alphabet[j]++;
		}
		j++;
	}

	for (int i = 0; i < 26; i++) {
		cout << alphabet[i] << " ";
	}
	


	return 0;

}

'Algorithm > Cases-Study' 카테고리의 다른 글

별 찍기 - 9  (0) 2020.05.04
개수 세기  (0) 2020.05.04
카드 역배치  (0) 2020.05.04
핸드폰 요금  (0) 2020.05.03
숫자의 개수  (0) 2020.05.03