forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.py
19 lines (16 loc) Β· 865 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# μμ°¨ νμ μμ€μ½λ ꡬν
def sequential_search(n, target, array):
# κ° μμλ₯Ό νλμ© νμΈνλ©°
for i in range(n):
# νμ¬μ μμκ° μ°Ύκ³ μ νλ μμμ λμΌν κ²½μ°
if array[i] == target:
return i + 1 # νμ¬μ μμΉ λ°ν (μΈλ±μ€λ 0λΆν° μμνλ―λ‘ 1 λνκΈ°)
return -1 # μμλ₯Ό μ°Ύμ§ λͺ»ν κ²½μ° -1 λ°ν
print("μμ±ν μμ κ°μλ₯Ό μ
λ ₯ν λ€μ ν μΉΈ λκ³ μ°Ύμ λ¬Έμμ΄μ μ
λ ₯νμΈμ.")
input_data = input().split()
n = int(input_data[0]) # μμμ κ°μ
target = input_data[1] # μ°Ύκ³ μ νλ λ¬Έμμ΄
print("μμ μ μ μμ κ°μλ§νΌ λ¬Έμμ΄μ μ
λ ₯νμΈμ. ꡬλΆμ λμ΄μ°κΈ° ν μΉΈμΌλ‘ ν©λλ€.")
array = input().split()
# μμ°¨ νμ μν κ²°κ³Ό μΆλ ₯
print(sequential_search(n, target, array))