2022.12.28
<Coding Test> 3 day
#15 배열 뒤집기
- 동적할당
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// num_list_len은 배열 num_list의 길이입니다.
int* solution(int num_list[], size_t num_list_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(sizeof(int) * num_list_len);
for(int i=0; i<num_list_len; i++)
{
answer[(num_list_len-1)-i]=num_list[i];
}
return answer;
}
코딩테스트 연습 - 배열 뒤집기 | 프로그래머스 스쿨 (programmers.co.kr)
입력한 배열(num_list)의 순서를 반대로 출력함.
#16 점의 위치 구하기
- if문
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// dot_len은 배열 dot의 길이입니다.
int solution(int dot[], size_t dot_len) {
int answer = 0;
if(dot[0]>0)
{
if(dot[1]>0)
answer=1;
else
answer=4;
}
else
{
if(dot[1]>0)
answer=2;
else
answer=3;
}
return answer;
}
코딩테스트 연습 - 점의 위치 구하기 | 프로그래머스 스쿨 (programmers.co.kr)
입력한 좌표(dot)의 x, y 부호를 통해서 해당 좌표가 속하는 사분면(answer)을 출력함.
'programmers' 카테고리의 다른 글
[c programmers] test 23-24 (0) | 2023.01.01 |
---|---|
[c programmers] test 18-22 (0) | 2022.12.31 |
[c programmers] test 17 (0) | 2022.12.29 |
[c programmers] test 10-14 (0) | 2022.12.27 |
[c programmers] test 01-09 (0) | 2022.12.26 |