백준 4641번: Doubles

danbibibi·2021년 11월 16일

문제

문제 바로가기> 백준 4641번: Doubles

풀이

반복문을 이용하여 배열을 돌면서 해당 원소*2가 배열 안에 있는지 확인하면 된다. python 배열의 in 을 이용하면 쉽게 해결할 수 있다.

def solution():
    import sys
    input = sys.stdin.readline
    while True:
        nums = list(map(int, input().split()))
        if len(nums)==1 and nums[0]==-1: break
        nums = nums[:-1]
        ans = 0
        for num in nums:
            if num*2 in nums: ans+=1
        print(ans)
solution()
profile
블로그 이전) https://danbibibi.tistory.com

0개의 댓글