

이거는 이해하기까지 시간이 좀 걸렸다. 인터넷 실명제를 도입하면 출제자를 알 수 있지 않으까 할 게 잇어.


부연 설명도 있는데 매개 변수의 범위와 조건에 맞지 않을 경우 리턴값을 -1로 하라는구만-!
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);
}
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 || ) // 빈칸
strcpy(answer, "-1");
else{
for(int i = 0; i < tile_length; i++)
answer[i] = com[i%6];
answer[tile_length]='\0';
}
return answer;
}

RRR / RRRGG / RRRGB / RRRGGBRRR / RRRGGBRRRGG / RRRGGBRRRGGB
출처 - EduAtoZ - Programming
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;
}
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);
}
