티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int time_table[], int time_table_len, int n) {
int answer = 0;
//빈칸
return answer;
}
int main() {
int time_table1[] = {1, 5, 1, 9};
int time_table_len1 = 4;
int n1 = 3;
int ret1 = solution(time_table1, time_table_len1, n1);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int time_table2[] = {4, 8, 2, 5, 4, 6, 7};
int time_table_len2 = 7;
int n2 = 4;
int ret2 = solution(time_table2, time_table_len2, n2);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}
완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int time_table[], int time_table_len, int n) {
int answer = 0;
int *arr = (int*)malloc(sizeof(int)*n);
for(int i=0;i<time_table_len;i++){
arr[i%n]+=time_table[i];
if(arr[i%n]>answer) answer = arr[i%n];
}
return answer;
}
int main() {
int time_table1[] = {1, 5, 1, 9};
int time_table_len1 = 4;
int n1 = 3;
int ret1 = solution(time_table1, time_table_len1, n1);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int time_table2[] = {4, 8, 2, 5, 4, 6, 7};
int time_table_len2 = 7;
int n2 = 4;
int ret2 = solution(time_table2, time_table_len2, n2);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}
예시
time_table | time_table_len | n | return | |
예시 #1 | [1,5,1,9] | 4 | 3 | 10 |
예시 #2 | [4,8,2,5,4,6,7] | 7 | 4 | 14 |
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 6차 2번_종이 나누어 주기 (C/C++) (0) | 2021.05.28 |
---|---|
[COS PRO 2급] 6차 1번_저는 따뜻한 날이 좋아요 (C/C++) (0) | 2021.05.28 |
[COS PRO 2급] 5차 9번_시험 등수 구하기 (C/C++) (0) | 2021.05.28 |
[COS PRO 2급] 5차 8번_상수도 요금 구하기 (C/C++) (0) | 2021.05.26 |
[COS PRO 2급] 5차 7번_계산대 두개에서 계산시간 구하기 (C/C++) (0) | 2021.05.26 |
댓글
공지사항
최근에 올라온 글
TAG
- YBM
- 배열
- 프로그래머스
- groomedu
- 구름에듀
- groom
- C++
- 연습문제
- 구름 기출문제
- cospro기출
- programmers
- 배열활용문제
- CosPro
- c언어 기출문제
- 구름에듀 기출문제
- 기출문제
- c언어
- 알고리즘
- lv1
- 코딩테스트
- 코스프로
- Java
- 1급
- lv2
- Cos Pro
- cospro기출문제
- 자바
- COSPRO 2급
- C
- YBM기출
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함