알고리즘/백준 풀이

[백준] 10807번: 개수 세기 (파이썬/Python)

제로타이 2023. 2. 18. 14:27

 

목차

     

    개요

    10807번: 개수 세기 (acmicpc.net)

    풀이

    1차원 배열에서 순회하는 문제. 

    일일히 반복문을 돌아서 찾아도 된다. 
    Counter나 count를 사용하는 방법도 있다!

    코드

    Counter 사용

    import sys
    from collections import Counter
    
    input = sys.stdin.readline
    N = int(input())
    lst = list(map(int, input().split()))
    v = int(input())
    
    counter_lst = Counter(lst)
    print(counter_lst[v])

    count 사용

    import sys
    
    input = sys.stdin.readline
    N = int(input())
    lst = list(map(int, input().split()))
    v = int(input())
    
    print(lst.count(v))