PythonCodeFight-Day12

Day_12

Intro

Q19. areEquallyStrong

Call two arms equally strong if the heaviest weights they each are able to lift are equal.

Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms.

Given your and your friend’s arms’ lifting capabilities find out if you two are equally strong.

제출 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight):
if yourLeft >= yourRight:
yourStrong = yourLeft
yourWeak = yourRight
else:
yourStrong = yourRight
yourWeak = yourLeft

if friendsLeft >= friendsRight:
friendsStrong = friendsLeft
friendsWeak = friendsRight
else:
friendsStrong = friendsRight
friendsWeak = friendsLeft

if (yourStrong == friendsStrong) and (yourWeak == friendsWeak):
return True
else:
return False

작성 흐름

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Case: true
# yourLeft = 10
# yourRight = 15
# friendsLeft = 15
# friendsRight = 10

# Case: false
yourLeft = 15
yourRight = 10
friendsLeft = 15
friendsRight = 9

# 맨 처음엔 둘의 합을 가지고 계산하는 조건을 넣으려고 했으나, 생각해보니 강한 팔과 약한 팔의 값이 같으면 합은 당연히 같은 거라서 따로 조건을 넣어줄 필요가 업성서 뺐음
# yourWeight = yourLeft + yourRight
# friendsWeight = friendsLeft + friendsRight

# 나의 강한 팔 값 찾기
if yourLeft >= yourRight:
yourStrong = yourLeft
yourWeak = yourRight
else:
yourStrong = yourRight
yourWeak = yourLeft

# 친구의 강한 팔 값 찾기
if friendsLeft >= friendsRight:
friendsStrong = friendsLeft
friendsWeak = friendsRight
else:
friendsStrong = friendsRight
friendsWeak = friendsLeft

# 비교해서 값 리턴하기
if (yourStrong == friendsStrong) and (yourWeak == friendsWeak):
print("true")
else:
print("false")

# if yourWeight == friendsWeight:
# print("True")
# else:
# print("False")

Q20. arrayMaximalAdjacentDifference

Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.

제출 코드

1
2
3
4
5
6
def arrayMaximalAdjacentDifference(inputArray):
difflist = []
for i in range(len(inputArray)-1):
difflist.append(abs(inputArray[i]-inputArray[i+1]))

return max(difflist)

작성 흐름

1
2
3
4
5
6
7
8
9
10
11
12
# Case
# inputArray = [2, 4, 1, 0]
inputArray = [-1, 4, 10, 3, -2]

# 차이 값을 넣을 리스트 선언
difflist = []

# 전체 배열 돌면서 차이의 절대값 넣기
for i in range(len(inputArray)-1):
difflist.append(abs(inputArray[i]-inputArray[i+1]))

print(max(difflist))