C++ 알고리즘 꿀팁

·2024년 1월 6일

algorithm

목록 보기
32/32

별건 아니고 그냥 공부하다가 소소한 지식들 보관용

  1. 전역변수에서 배열을 선언하면 알아서 0으로 초기화된다.
  2. 다음과 같이 배열를 이용하면 빈도수를 측정 가능하다.
int freq[26];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for(auto c : s)
    freq[c-'a']++;
  for(int i = 0; i < 26; i++)
    cout << freq[i] << ' ';
}
profile
풀스택 호소인

0개의 댓글