문제) 백준 - 문자열 - 알파벳 개수
https://www.acmicpc.net/problem/10808
10808번: 알파벳 개수
단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.
www.acmicpc.net
문자열의 최대 길이가 100이므로 모든 문자열을 순회하면서 세우 주면 되는 쉬운 문제였습니다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#define endl "\n" | |
#define MAX 1001 | |
#define INF 987654321 | |
#define MOD 1001 | |
#define ll long long | |
#define int ll | |
using namespace std; | |
typedef pair<int, int> p; | |
signed main() { | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); cout.tie(0); | |
int cnt[26] = { 0, }; | |
string s; cin >> s; | |
for (int i = 0; i < s.size(); ++i) | |
cnt[s[i] - 'a']++; | |
for (int i = 0; i < 26; ++i) | |
cout << cnt[i] << " "; | |
return 0; | |
} |
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 17829번 - 222-풀링 (C++) 문제 및 풀이 (0) | 2022.01.25 |
---|---|
[백준] 1474번 - 밑 줄 (C++) 문제 및 풀이 (0) | 2022.01.25 |
[백준] 5427번 - 불 (C++) 문제 및 풀이 (0) | 2022.01.24 |
[백준] 4358번 - 생태학 (C++) 문제 및 풀이 (0) | 2022.01.23 |
[백준] 3151번 - 합이 0 (C++) 문제 및 풀이 (0) | 2022.01.23 |
댓글