목록알고리즘 (98)
forest_moon
문제 설명 정수가 들어 있는 배열 num_list가 매개변수로 주어집니다. num_list의 원소의 순서를 거꾸로 뒤집은 배열을 return하도록 solution 함수를 완성해주세요. 제한사항 1 ≤ num_list의 길이 ≤ 1,000 0 ≤ num_list의 원소 ≤ 1,000 입출력 예 설명 입출력 예 #1 num_list가 [1, 2, 3, 4, 5]이므로 순서를 거꾸로 뒤집은 배열 [5, 4, 3, 2, 1]을 return합니다. 입출력 예 #2 num_list가 [1, 1, 1, 1, 1, 2]이므로 순서를 거꾸로 뒤집은 배열 [2, 1, 1, 1, 1, 1]을 return합니다. 입출력 예 #3 num_list가 [1, 0, 1, 1, 1, 3, 5]이므로 순서를 거꾸로 뒤집은 배열 [5, ..
문제 설명 머쓱이는 추운 날에도 아이스 아메리카노만 마십니다. 아이스 아메리카노는 한잔에 5,500원입니다. 머쓱이가 가지고 있는 돈 money가 매개변수로 주어질 때, 머쓱이가 최대로 마실 수 있는 아메리카노의 잔 수와 남는 돈을 순서대로 담은 배열을 return 하도록 solution 함수를 완성해보세요. 제한사항 0
문제 설명 머쓱이네 옷가게는 10만 원 이상 사면 5%, 30만 원 이상 사면 10%, 50만 원 이상 사면 20%를 할인해줍니다. 구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return 하도록 solution 함수를 완성해보세요. 제한사항 10 ≤ price ≤ 1,000,000 price는 10원 단위로(1의 자리가 0) 주어집니다. 소수점 이하를 버린 정수를 return합니다. 입출력 예 설명 입출력 예 #1 150,000원에서 5%를 할인한 142,500원을 return 합니다. 입출력 예 #2 580,000원에서 20%를 할인한 464,000원을 return 합니다. class Solution { public int solution(int price) { int answer ..
문제 설명 정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소의 평균값을 return하도록 solution 함수를 완성해주세요. 제한사항 0 ≤ numbers의 원소 ≤ 1,000 1 ≤ numbers의 길이 ≤ 100 정답의 소수 부분이 .0 또는 .5인 경우만 입력으로 주어집니다. 입출력 예 설명 입출력 예 #1 numbers의 원소들의 평균 값은 5.5입니다. 입출력 예 #2 numbers의 원소들의 평균 값은 94.0입니다. class Solution { public double solution(int[] numbers) { double answer = 0; int sum = 0; for(int i=0 ; i < numbers.length ; i ++){ sum += numbe..
피자 나눠 먹기 (3) 문제 설명 머쓱이네 피자가게는 피자를 두 조각에서 열 조각까지 원하는 조각 수로 잘라줍니다. 피자 조각 수 slice와 피자를 먹는 사람의 수 n이 매개변수로 주어질 때, n명의 사람이 최소 한 조각 이상 피자를 먹으려면 최소 몇 판의 피자를 시켜야 하는지를 return 하도록 solution 함수를 완성해보세요. 제한사항 2 ≤ slice ≤ 10 1 ≤ n ≤ 100 입출력 예 설명 입출력 예 #1 10명이 7조각으로 자른 피자를 한 조각 이상씩 먹으려면 최소 2판을 시켜야 합니다. 입출력 예 #2 12명이 4조각으로 자른 피자를 한 조각 이상씩 먹으려면 최소 3판을 시켜야 합니다. class Solution { public int solution(int slice, int n..
문제 설명 머쓱이네 피자가게는 피자를 여섯 조각으로 잘라 줍니다. 피자를 나눠먹을 사람의 수 n이 매개변수로 주어질 때, n명이 주문한 피자를 남기지 않고 모두 같은 수의 피자 조각을 먹어야 한다면 최소 몇 판을 시켜야 하는지를 return 하도록 solution 함수를 완성해보세요. 제한사항 1 ≤ n ≤ 100 입출력 예 설명 입출력 예 #1 6명이 모두 같은 양을 먹기 위해 한 판을 시켜야 피자가 6조각으로 모두 한 조각씩 먹을 수 있습니다. 입출력 예 #2 10명이 모두 같은 양을 먹기 위해 최소 5판을 시켜야 피자가 30조각으로 모두 세 조각씩 먹을 수 있습니다. 입출력 예 #3 4명이 모두 같은 양을 먹기 위해 최소 2판을 시키면 피자가 12조각으로 모두 세 조각씩 먹을 수 있습니다. clas..
문제 설명 머쓱이네 피자가게는 피자를 일곱 조각으로 잘라 줍니다. 피자를 나눠먹을 사람의 수 n이 주어질 때, 모든 사람이 피자를 한 조각 이상 먹기 위해 필요한 피자의 수를 return 하는 solution 함수를 완성해보세요. 제한사항 1 ≤ n ≤ 100 입출력 예 설명 입출력 예 #1 7명이 최소 한 조각씩 먹기 위해서 최소 1판이 필요합니다. 입출력 예 #2 1명은 최소 한 조각을 먹기 위해 1판이 필요합니다. 입출력 예 #3 15명이 최소 한 조각씩 먹기 위해서 최소 3판이 필요합니다. class Solution { public int solution(int n) { int answer = (n % 7 == 0) ? n / 7 : n / 7 + 1; return answer; } } 간단하게 ..
문제 설명 머쓱이는 40살인 선생님이 몇 년도에 태어났는지 궁금해졌습니다. 나이 age가 주어질 때, 2022년을 기준 출생 연도를 return 하는 solution 함수를 완성해주세요. 제한사항 0 < age ≤ 120 나이는 태어난 연도에 1살이며 1년마다 1씩 증가합니다. 입출력 예 설명 입출력 예 #1 2022년 기준 40살이므로 1983년생입니다. 입출력 예 #2 2022년 기준 23살이므로 2000년생입니다. class Solution { public int solution(int age) { int answer =(2022 - age + 1); return answer ; } } answer에 나이 +10 해놓고 왜 뭐가 잘못된건가 보고있었네 .. 후 .. 지문만 잘읽을게 아니라 코드도 다시..