티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num_apple, int num_carrot, int k) {
int answer = 0;
if(num_apple < 3 * num_carrot)
answer = num_apple / 3;
else
answer = num_carrot;
num_apple -= 3 * answer;
num_carrot -= answer;
for(int i = 0; k - (num_apple + num_carrot + i) > 0; i++)
if(i % 4 == 0)
answer++;
return answer;
}
int main() {
int num_apple1 = 5;
int num_carrot1 = 1;
int k1 = 2;
int ret1 = solution(num_apple1, num_carrot1, k1);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int num_apple2 = 10;
int num_carrot2 = 5;
int k2 = 4;
int ret2 = solution(num_apple2, num_carrot2, k2);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}
완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num_apple, int num_carrot, int k) {
int answer = 0;
if(num_apple < 3 * num_carrot)
answer = num_apple / 3;
else
answer = num_carrot;
num_apple -= 3 * answer;
num_carrot -= answer;
for(int i = 0; k - (num_apple + num_carrot + i) > 0; i++)
if(i % 4 == 0)
answer--;
return answer;
}
int main() {
int num_apple1 = 5;
int num_carrot1 = 1;
int k1 = 2;
int ret1 = solution(num_apple1, num_carrot1, k1);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int num_apple2 = 10;
int num_carrot2 = 5;
int k2 = 4;
int ret2 = solution(num_apple2, num_carrot2, k2);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}
결과
num_apple | num_carrot_len | k | return | |
예시 #1 | 5 | 1 | 2 | 1 |
예시 #2 | 10 | 5 | 4 | 2 |
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 3차 9번_주차장에 몇대가 들어올수 있는거야? (C/C++) (0) | 2021.05.17 |
---|---|
[COS PRO 2급] 3차 8번_TV 애청자 A씨 (C/C++) (0) | 2021.05.16 |
[COS PRO 2급] 3차 6번_타일 색칠 방법 구하기 (C/C++) (0) | 2021.05.15 |
[COS PRO 2급] 3차 5번_여행객의 총 교통비 구하기 (C/C++) (0) | 2021.05.15 |
[COS PRO 2급] 3차 3번_체조 선수의 점수 구해주기 (C/C++) (0) | 2021.05.14 |
댓글
공지사항
최근에 올라온 글
TAG
- C
- 1급
- YBM
- 프로그래머스
- COSPRO 2급
- 코스프로
- 기출문제
- groomedu
- CosPro
- 구름 기출문제
- 알고리즘
- c언어 기출문제
- Java
- 연습문제
- 구름에듀 기출문제
- c언어
- YBM기출
- 자바
- Cos Pro
- 배열
- 구름에듀
- 코딩테스트
- lv1
- cospro기출문제
- groom
- lv2
- C++
- cospro기출
- 배열활용문제
- programmers
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함