본문 바로가기

programmers

[c programmers] test 18-22

 
2022.12.30

 

<Coding Test> 5 day

 

#18 배열 원소의 길이

 

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

// strlist_len은 배열 strlist의 길이입니다.
// 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요.
int* solution(const char* strlist[], size_t strlist_len) {
    // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
    int* answer = (int*)malloc(sizeof(int)*strlist_len);
    for(int i=0; i<strlist_len; i++)
    {
        answer[i]=strlen(strlist[i]);
    }
    return answer;
}

코딩테스트 연습 - 배열 원소의 길이 | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#19 피자 나눠 먹기(3)

 

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int slice, int n) {
    int answer = 0;
    if(n%slice==0)
    {
        answer=n/slice;
    }
    else
    {
        answer=n/slice+1;
    }
    return answer;
}

코딩테스트 연습 - 피자 나눠 먹기 (3) | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#20 아이스 아메리카노

 

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int* solution(int money) {
    // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
    int* answer = (int*)malloc(sizeof(int)*2);
    
    answer[0]=money/5500;
    answer[1]=money-(5500*answer[0]);
    
    return answer;
}

코딩테스트 연습 - 아이스 아메리카노 | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#21 배열 두 배 만들기

 

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

// numbers_len은 배열 numbers의 길이입니다.
int* solution(int numbers[], size_t numbers_len) {
    // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
    int* answer = (int*)malloc(sizeof(int)*numbers_len);
    for(int i=0; i<numbers_len; i++)
    {
    
        answer[i]=numbers[i]*2;
    }
    return answer;
}

코딩테스트 연습 - 배열 두 배 만들기 | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#22 짝수 홀수 개수

#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)*2);
    answer[0]=0;
    answer[1]=0;
    for(int i=0; i<num_list_len; i++)
    {
        if(num_list[i]%2==0)
        {
            answer[0]++;
        }
        else
        {
            answer[1]++;
        }
        
    }
    return answer;
}

코딩테스트 연습 - 짝수 홀수 개수 | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

'programmers' 카테고리의 다른 글

[c programmers] test 25  (0) 2023.01.01
[c programmers] test 23-24  (0) 2023.01.01
[c programmers] test 17  (0) 2022.12.29
[c programmers] test 15-16  (0) 2022.12.28
[c programmers] test 10-14  (0) 2022.12.27