본문 바로가기
CodingTest

프로그래머스 - 코딩테스트 입문 Day 4

by Jiwon_Loopy 2025. 4. 12.
반응형

피자 나눠먹기 (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;
    }
}

피자 나눠먹기 (2)


class Solution {
	public static int solution(int n) {
		int p = n;
        //6과 n의 최소 공배수
        while(n % 6 != 0){
            n += p;
        }
        return n/6;
    }  
}

피자 나눠먹기 (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 double solution(int[] numbers) {
        double answer = 0;
        for(int n : numbers){
            answer += n;
        }
        return answer / numbers.length;
    }
}
728x90
반응형