본문 바로가기
python-algorithm

백준 4641 Doubles

by 무적김두칠 2022. 10. 29.

https://www.acmicpc.net/problem/4641

 

4641번: Doubles

2~15개의 서로 다른 자연수로 이루어진 리스트가 있을 때, 이들 중 리스트 안에 자신의 정확히 2배인 수가 있는 수의 개수를 구하여라. 예를 들어, 리스트가 "1 4 3 2 9 7 18 22"라면 2가 1의 2배, 4가 2의

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
def sol(nums):
    answer=-1
    for i in nums:
        if i*2 in nums:
            answer+=1
    return answer
while 1:
    nums=list(map(int, input().split()))
    if nums==[-1]:
        break
    else:
        print(sol(nums))
cs

자기 자신의 2배가 되는 숫자 선형탐색 하시면됩니당

Search linearly numbers which are twice themselves

반응형

'python-algorithm' 카테고리의 다른 글

백준 9455 박스  (0) 2022.10.29
백준 2456 나는 학급회장이다  (0) 2022.10.29
백준 13235 팰린드롬  (0) 2022.10.28
백준 14696 딱지놀이  (0) 2022.10.28
백준 2947 나무 조각  (0) 2022.10.28

댓글