본문 바로가기

하루회고 ( *ฅ́˘ฅ̀*)/프로그래머스 (๑ ́ᄇ`๑)

C#)각도기

<문제 설명>

<나의 풀이>

<다른사람의 풀이>

1)
using System;

public class Solution {
    public int solution(int angle) {
        int answer = angle < 90 ? 1 : angle == 90 ? 2 : angle < 180 ? 3 : 4;
        return answer;
    }
}

2)
using System;

public class Solution {
    public int solution(int angle) {
        int answer = angle / 90 + 1 + (angle > 90 ? 1 : 0);
        return answer;
    }
}

3)
using System;

public class Solution {
        public int solution(int angle)
        {
            int answer = 0;

            if(angle > 0 && angle <= 180)
            {
                if (0 < angle && angle < 90) answer = 1;
                else if (angle == 90) answer = 2;
                else if (90 < angle && angle < 180) answer = 3;
                else if (angle == 180) answer = 4;
            }
            return answer;

        }
}

'하루회고 ( *ฅ́˘ฅ̀*) > 프로그래머스 (๑ ́ᄇ`๑)' 카테고리의 다른 글

C#)편지  (0) 2024.07.29
C#)배열의 평균  (0) 2024.07.16
C#)두 수의 나눗셈  (0) 2024.06.11
C#)짝수의 합  (1) 2024.06.10
C#)두 수의 합  (1) 2024.06.09