티스토리 뷰

 

구름에듀 4차 1번 문제




주어진 코드

#include <stdio.h> #include <stdbool.h> #include <stdlib.h> int* solution(char* schedule[], int schedule_len) { int x_count = 0; for(int i=0; i<10; i++) if(schedule[i][0] == 'X') x_count++; int* answer = (int*)malloc(sizeof(int)*x_count); for(int i=0, j=0; i<10; i++) { if(schedule[i][0] == 'X') { answer[ ] = ; //빈칸 } } return answer; } int main() { char* schedule[] = {"O", "X", "X", "O", "O", "O", "X", "O", "X", "X"}; int* ret = solution(schedule, 10); printf("solution 함수의 반환 값은 "); for(int i=0; i<5; i++) printf("%d, ", ret[i]); printf("입니다."); }




완성 코드

#include <stdio.h> #include <stdbool.h> #include <stdlib.h> int* solution(char* schedule[], int schedule_len) { int x_count = 0; for(int i=0; i<10; i++) if(schedule[i][0] == 'X') x_count++; int* answer = (int*)malloc(sizeof(int)*x_count); for(int i=0, j=0; i<10; i++) { if(schedule[i][0] == 'X') { answer[j++] = i+1; } } return answer; } int main() { char* schedule[] = {"O", "X", "X", "O", "O", "O", "X", "O", "X", "X"}; int* ret = solution(schedule, 10); printf("solution 함수의 반환 값은 "); for(int i=0; i<5; i++) printf("%d, ", ret[i]); printf("입니다."); }





GroomEdu

 

goorm

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

www.goorm.io

 

댓글