2018년 4월 9일 월요일

[python][hackerrank] Find Digits (3 ways)



input1 = '1012'

number = int(input1)
n = len(input1)
res = 0
for i in range(n):
    _in = int(input1[i])
    if (_in != 0 and number % _in == 0):
        res += 1
       
print(res)

input2 ='1012'
number2 = int(input2)
a = (int(x) for x in input1)
res2 = 0
for i in a:
    if i != 0 and (number2 % i) == 0:
        res2 += 1
print(res2)

input3 = '1012'
number3 = int(input3)
# int_generator = (int(x) for x in input1)
res3 = sum( 1 for y in (int(x) for x in input1)
                    if y != 0 and number3 % y == 0)

print(res3)

댓글 없음:

댓글 쓰기