#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// numbers_len은 배열 numbers의 길이입니다.
int solution(int numbers[], size_t numbers_len) {
int answer = 0;
int check[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int *result = (int*)malloc(sizeof(int)*numbers_len); // 정수 배열 동적 할당
for(int i=0; i<numbers_len; i++)
{
result[i] = numbers[i];
}
for(int i=0; i<numbers_len; i++)
{
for(int j=0; j<10; j++)
{
if(result[i] == check[j])
{
check[j] = 0;
}
}
}
for(int i=0; i<10; i++)
{
if(check[i] != 0)
{
answer += check[i];
}
}
return answer;
}
*******************************************************************************************************
동적 할당 하고나서 입력으로 주어지는 배열 값을
동적 할당 한 배열에 넣지 않아서 뭐가 문제인지 한참 찾았었다..
이상한 실수가 넘 많네.
*******************************************************************************************************
'공부' 카테고리의 다른 글
| (프로그래머스)음양 더하기 (0) | 2021.10.08 |
|---|---|
| (프로그래머스)로또의 최고 순위와 최저 순위 (0) | 2021.10.08 |
| (프로그래머스)숫자 문자열과 영단어 (0) | 2021.10.06 |
| 최소공배수(lcm), 최대공약수(gcd) (0) | 2018.03.13 |
| Dynamic Programming (0) | 2017.09.14 |
댓글