[algorithm] 백준 10807번 개수 세기

2026. 1. 10. 12:35·algorithm/배열
반응형

 

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int a,b,c;
    int arr[100] = {};
    cin >> a;
    
    for (int i=0; i<a; i++)
        {
            cin >> b;
            arr[i] = b;
        }
    cin >> c;
    int cnt = 0;
    
    for (int i=0; i<a; i++)
        {
            if (arr[i] == c) cnt++;
        }
    cout << cnt;

    return 0;
}

 

N이 1 ~ 100까지므로 배열을 100의 크기로 선언해주고

배열을 돌면서 주어진 수와 일치하는 지 판단하고

일치하면 개수를 카운트해주는 방식으로 하는 간단한 문제이다

 

중간에 cnt값을 0으로 초기화해주지 않으면 

쓰레기값이 들어가고 

전역변수로 설정한다면 0으로 자동초기화되므로 굳이 초기화하지 않아도 된다

반응형

'algorithm > 배열' 카테고리의 다른 글

[algorithm] 백준 11328번 Strfry  (0) 2026.01.10
[algorithm] 백준 13300번 방 배정  (0) 2026.01.10
[algorithm] 백준 1475번 방 번호  (0) 2026.01.10
[algorithm] 백준 2577번 숫자의 개수  (0) 2026.01.10
[algorithm] 백준 10808번 알파벳 개수  (0) 2026.01.10
'algorithm/배열' 카테고리의 다른 글
  • [algorithm] 백준 13300번 방 배정
  • [algorithm] 백준 1475번 방 번호
  • [algorithm] 백준 2577번 숫자의 개수
  • [algorithm] 백준 10808번 알파벳 개수
20puddle
20puddle
20puddle 님의 블로그 입니다.
  • 20puddle
    20puddle 님의 블로그
    20puddle
  • 전체
    오늘
    어제
    • 분류 전체보기 (100)
      • Spring boot (5)
      • git & github (5)
      • algorithm (47)
        • theory (3)
        • 배열 (7)
        • 연결 리스트 (3)
        • 스택 (5)
        • 큐 (3)
        • 덱 (2)
        • 기초 코드 (19)
        • BFS (5)
      • AI (43)
        • Machine Learning (35)
        • Deep Learning (8)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    github
    게시판
    그레디언트 클리핑
    홀드아웃 검증
    Java
    list
    연결리스트
    Spring Boot
    알고리즘
    git
    DL
    AI
    딥러닝
    머신러닝
    오프라인 학습
    백준
    ML
    Aimers
    인공지능
    주성분변환
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.3
20puddle
[algorithm] 백준 10807번 개수 세기
상단으로

티스토리툴바