티스토리 뷰
주어진 코드
#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("입니다."); }
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 4차 4번_조교의 수 구하기 (C/C++) (0) | 2021.05.19 |
---|---|
[COS PRO 2급] 4차 3번_획득 점수 구하기. 도박은 안되요 (C/C++) (0) | 2021.05.19 |
[COS PRO 2급] 4차 2번_시험 합격자가 몇명이지? (C/C++) (0) | 2021.05.18 |
[COS PRO 2급] 3차 10번_내 절반이 여기에 있는거야? (C/C++) (0) | 2021.05.17 |
[COS PRO 2급] 3차 9번_주차장에 몇대가 들어올수 있는거야? (C/C++) (0) | 2021.05.17 |
댓글
공지사항
최근에 올라온 글
TAG
- 구름에듀 기출문제
- c언어
- COSPRO 2급
- 배열활용문제
- 자바
- 구름에듀
- 연습문제
- CosPro
- C++
- 기출문제
- Java
- lv2
- 1급
- cospro기출
- cospro기출문제
- groomedu
- 코딩테스트
- 프로그래머스
- YBM기출
- 구름 기출문제
- Cos Pro
- lv1
- groom
- c언어 기출문제
- YBM
- programmers
- 코스프로
- 배열
- 알고리즘
- C
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함