알고리즘 0레벨 풀이 - 3/14

송현진·2023년 3월 14일
0

알고리즘

목록 보기
2/50
  • 양꼬치
class Solution {
    public int solution(int n, int k) {
        int answer = 0;
        answer = n*12000+k*2000-n/10*2000;
        return answer;
    }
}
  • 피자나눠먹기(1)
class Solution {
    public int solution(int n) {
        int answer = 0;
        if(n%7==0){
            answer = n/7;
        }else{
            answer = n/7 + 1;
        }
        return answer;
    }
}
  • 피자나눠먹기(3)
class Solution {
    public int solution(int slice, int n) {
        int answer = 0;
        if(n%slice == 0){
            answer = n / slice;
        }else{
            answer = n / slice + 1;
        }
        return answer;
    }
}
  • 점의 위치 구하기
class Solution {
    public int solution(int[] dot) {
        int answer = 0;
        if(dot[0] > 0 && dot[1] > 0){
            answer = 1;
        }else if(dot[0] < 0 && dot[1] > 0){
            answer = 2;
        }else if(dot[0] < 0 && dot[1] < 0){
            answer = 3;
        }else{
            answer=4;
        }
        return answer;
    }
}
  • 아이스 아메리카노
class Solution {
    public int[] solution(int money) {
        int[] answer = new int[2];
        answer[0] = money / 5500;
        answer[1] = money % 5500;
        return answer;
    }
}
  • 옷가게 할인받기
class Solution {
    public int solution(int price) {
        int answer = 0;
        if(price >= 500000){
            answer = (int)(price*0.8);
        }else if(price >= 300000){
            answer = (int)(price*0.9);
        }else if(price >= 100000){
            answer = (int)(price*0.95);
        }else{
            answer = price;
        }
        return answer;
    }
}
  • 제곱수 판별하기
class Solution {
    public int solution(int n) {
        int answer = 0;
         for(int i=0; i<= 1000; i++) {
            if(i*i == n )
                return answer = 1;
        }
        return answer = 2;
    }
}

✏️ 제곱수 판별하기는 생각하는 데 꽤 시간이 걸렸다. 다른 분들은 Math.sqrt()라는
함수를 써서 구현하셔서 그런 함수가 있다는 걸 알게되었다.
Math.sqrt(n)은 n의 제곱근을 구해주는 함수다. 입력값과 출력값 모두 double형이다.

profile
개발자가 되고 싶은 취준생

0개의 댓글