[[TableOfContents]] == 코딩테스트 1단계 == === 두 개 뽑아서 더하기 === {{{ #include #include #include int compare(void *a,void *b); int* solution(int numbers[], size_t numbers_len) { qsort(numbers,numbers_len,sizeof(int),compare); int* temp = (int*)malloc(sizeof(int)*201); memset(temp,0,sizeof(int)); int i,j,k,n=0; for (i = 0; i < numbers_len - 1; ++i){ for(j = i+1; j < numbers_len; ++j){ int count = 0; for(k=0; k < n; ++k){ if(temp[k] == numbers [i] + numbers[j]){ ++count; } } if(count == 0){ temp[n] = numbers [i] + numbers[j]; ++n; } } } qsort(temp,n,sizeof(int),compare); int* answer = (int*)malloc(sizeof(int)*n); for (i = 0; i < n; ++i){ answer[i]= temp[i]; } free(temp); return answer; } int compare(void *a,void *b){ int num1 = *(int *)a; int num2 = *(int *)b; return num1 - num2; } }}}