[코딩테스트 - 백준 10808번 C++] 알파벳 개수

최초로 (cho)·2023년 2월 9일
0

코딩테스트

목록 보기
5/9
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);
    
    char a = 'a';
    cout << (int)a << "\n";
    return 0;
}

알파벳 총 개수 26개
아스키코드
대문자 A : 65
소문자 a : 97

배열을 이용하였다.

#include <bits/stdc++.h>
using namespace std;

string str;
int cnt[26];
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);
    
    cin >> str;
    for(char a : str){
        cnt[a - 'a']++;
    }
    for(int i = 0; i < 26; i++) cout << cnt[i] << " ";

    return 0;
}
profile
relentless

0개의 댓글