코딩/백준 문제 (브론즈)

[백준/10807번/파이썬] 개수 세기 풀이

룻밤 2023. 2. 13. 19:39


합계를 위한 변수 생성

n = int(input())        # 정수의 개수 변수
n_list = list(map(int, input().split()))    # 정수의 리스트
v = int(input())        # 찾고자 하는 정수
total = 0               # 정수의 개수

for i in n_list:        # 리스트를 하나씩 반복
    if v == i:          # 찾고자 하는 정수와 i 값이 같다면
        total += 1      # 정수 개수에 +1

print(total)            # 정수 개수 출력

 

count 함수

n = int(input())        # 정수의 개수 변수
n_list = list(map(int, input().split()))     # 찾고자 하는 정수
v = int(input())        # 정수의 개수

print(n_list.count(v))  # n_list 리스트에서 v의 개수를 출력