Coding Test/Problem_solving

[백준] 10808 알파벳 개수

Blueberry_Child 2021. 3. 9. 16:39

www.acmicpc.net/problem/10808

 

10808번: 알파벳 개수

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

www.acmicpc.net

 

c언어와 c++을 같이 해보았다.

 

이 문제는 쉬웠는데 

확실히 같은 코드인데 

c++의 메모리가 많이 차지하는걸 알 수 있다. 

 

코드 c++ 

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

int main() {
	string input;
	int answer[26] = { 0 };
	
	cin >> input;
	for(int i = 0; i < input.length(); i++){
		answer[input.at(i) - 'a']+= 1;
	}
	for (int i = 0; i < 26; i++) {
		printf("%d ", answer[i]);
	}
	return 0;
}

코드 c

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

int main() {
	string input;
	int answer[26] = { 0 };

	cin >> input;
	for(int i = 0; i < input.length(); i++){
		answer[input.at(i) - 'a']+= 1;
	}
	for (int i = 0; i < 26; i++) {
		printf("%d ", answer[i]);
	}
	return 0;
}