Posts [BOJ 백준] 10808번 알파벳 개수 / C++
Post
Cancel

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


Contents



문제


문제를 보시려면 링크를 클릭해주세요.


풀이


알파벳 소문자 a~z는 아스키코드 상에서 97~122임을 이용하여, 각 알파벳 등장횟수 만큼 0으로 초기화된 배열의 원소값을 증가시켰습니다.


소스 코드


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
#include <iostream>
#include <vector>
#include<string>
using namespace std;

#define N 26

int main(int argc, char**argv) {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	vector<int> ans(N);
	string str="";
	
	cin >> str;
	

	for(int i=0; i<str.size(); i++){
		ans[str.at(i)-97]++;
	}
	
		
	for(int i=0; i<N; i++){
		cout << ans[i] <<" ";
	}
	
	return 0;
}



This post is licensed under CC BY 4.0 by the author.

[BOJ 백준] 10804번 카드 역배치 / C++

[WebLogic] 웹로직 HTTP method 제한 방법

Comments powered by Disqus.