본문 바로가기

Algorithm/Code Fights (Code Signal)

Aracade Intro #19 AreEquallyStrong. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

 Aracade Intro #19 AreEquallyStrong. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar



Q.


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.



 둘이 똑같은 무게를 들수 있으면 동등한 힘을 가졌다고 본다.


두사람이 양팔로 들수 있는 최대무게가 같고, 약한 힘을 가진 팔의 무게가 같으면 두 사람이 같은 힘을 가졌다고 본다.


 주어진 친구와 너의 양쪽 팔 힘을 보고 같은 힘을 가졌는지 확인해라.


e.g. 


Input -> yourLeft = 10, yourRight = 15, friendsLeft = 15, and friendsRight = 10

Output -> areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;


Input -> yourLeft = 15, yourRight = 10, friendsLeft = 15, and friendsRight = 10

Output -> areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;


Input -> yourLeft = 15, yourRight = 10, friendsLeft = 15, and friendsRight = 9

Output -> areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = false.



 처음에 풀었던 코드를 보니 엄청 길게 이상하게 풀어놨던데.. 문제 읽다가 다시 수정함

I solved it using weird way, so i recoded after reading Question again.



//Process

//1. Input my left strength, right strength, friend's left strength, right strength

//2. Check if each people's sum of strength are the same or not

// 2.1. If it's same -> Check if any strength of arm has the same strength with any friend's arm.

//  2.1.1. If so -> true

//3. Return result boolean



//Process

//1. 내 왼팔힘, 오른팔힘, 친구 왼팔힘, 오른팔힘 입력받는다.

//2. 내 팔힘의 합과 친구 팔힘의 합이 같은지 확인한다.

// 2.1. 같으면 -> 내 한쪽 팔 힘이 친구 양쪽 팔힘 중에 같은 값이 있는지 확인한다.

//  2.1.1. -> 있으면 true

//3. 결과를 반환한다.



코드.. 코드를 보자!!!

Code.. let me see code!!!




bool areEquallyStrong(int yourLeft, int yourRight, int friendsLeft, int friendsRight) {

    

    bool answer = false;

    

    if (yourLeft + yourRight == friendsLeft + friendsRight)

    {

        if (yourLeft == friendsLeft || yourLeft == friendsRight)

        {

            answer = true;

        }

    }

    return answer;

}



Something else...



2018/10/27 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #19 AreEquallyStrong, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #18 PalindromeRearranging, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #17 ArrayChange, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #16 AreSimilar?, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #15 AddBorder, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #14 AlternatingSums, Codefights, CodeSignal

2018/10/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #13 ReverseParentheses, Codefights, CodeSignal

2018/10/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #12 SortByHeight

2018/10/06 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #11 IsLucky

2018/10/03 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #10 CommonCharacterCount

2018/09/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #9 AllLongestStrings

2018/09/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #8 MatrixElementsSum

2018/09/23 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #7 AlmostIncreasingSequence

2018/09/22 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #6 MakeArrayConsecutive2

2018/09/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #5 ShapeArea

2018/09/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #4 AdjacentElementsProduct

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #3 CheckPalindrome

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #2 CenturyFromYear

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #1 Add