본문 바로가기

cospro2급/cospro_3차

2021-05-15

cospro 2급 6번 문제

타일 색칠 방법 구하기

 

문제 설명

 

매개변수 설명

 

return 값 설명

 

예시

 

예시 설명

 

코드 설명

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

char* solution(int tile_length) {
    char* answer = (char*) malloc(sizeof(char) * (tile_length+1) );  //동적할당
    char com[6] = {'R','R','R','G','G','B'}; //이 순서대로 타일을 칠함 
    if(tile_length%6 == 1 || tile_length%6 == 2 || tile_length%6==4) 
        strcpy(answer, "-1");
    else{
        for(int i = 0; i < tile_length; i++)
            answer[i] = com[i%6]; 
        answer[tile_length]='\0';
    }
    return answer;
}

int main() {
    int tile_length1 = 11;
    char* ret1 = solution(tile_length1);


    printf("solution 함수의 반환 값은 %s 입니다.\n", ret1);
    
    int tile_length2 = 16;
    char* ret2 = solution(tile_length2);


    printf("solution 함수의 반환 값은 %s 입니다.\n", ret2);
}

 

 

 

goorm

구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.

www.goorm.io

 

'cospro2급 > cospro_3차' 카테고리의 다른 글

2021-05-16  (0) 2021.05.16
2021-05-16  (0) 2021.05.16
2021-05-15  (0) 2021.05.15
2021-05-14  (0) 2021.05.14
2021-05-13  (0) 2021.05.13