티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int calorie[], int calorie_len) {
int min_cal = 0;
int answer = 0;
for (int i = 0; i < calorie_len; i++) {
if (calorie[i] > min_cal)
answer += calorie[i] - min_cal;
else
min_cal = calorie[i];
}
return answer;
}
int main() {
int calorie[] = { 713, 665, 873, 500, 751 };
int ret = solution(calorie, 5);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int calorie[], int calorie_len) {
int min_cal = calorie[0];
int answer = 0;
for (int i = 0; i < calorie_len; i++) {
if (calorie[i] > min_cal)
answer += calorie[i] - min_cal;
else
min_cal = calorie[i];
}
return answer;
}
int main() {
int calorie[] = { 713, 665, 873, 500, 751 };
int ret = solution(calorie, 5);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
예시
calorie | calorie_len | return |
[713, 665, 873, 500, 751] | 5 | 459 |
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 4차 7번_오른 점수와 떨어진 점수 구하기 (C/C++) (0) | 2021.05.21 |
---|---|
[COS PRO 2급] 4차 8번_누가 반장이 될까요 (C/C++) (0) | 2021.05.21 |
[COS PRO 2급] 4차 6번_여러분이 열심히 모은 point, 돌려 드립니다 (C/C++) (0) | 2021.05.20 |
[COS PRO 2급] 4차 4번_조교의 수 구하기 (C/C++) (0) | 2021.05.19 |
[COS PRO 2급] 4차 3번_획득 점수 구하기. 도박은 안되요 (C/C++) (0) | 2021.05.19 |
댓글
공지사항
최근에 올라온 글
TAG
- C++
- 연습문제
- Cos Pro
- CosPro
- groom
- 배열활용문제
- 프로그래머스
- 코딩테스트
- c언어 기출문제
- YBM기출
- 코스프로
- 1급
- lv1
- cospro기출
- c언어
- lv2
- C
- 배열
- 기출문제
- YBM
- programmers
- 구름 기출문제
- groomedu
- 자바
- cospro기출문제
- 알고리즘
- 구름에듀 기출문제
- COSPRO 2급
- 구름에듀
- Java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함