티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int compare(const void* a, const void* b) {
return (*(int*)b - *(int*)a);
}
int func_a(int scores[], int scores_len, int score) {
for (int rank = 0; rank < scores_len; rank++)
if (scores[rank] == score)
return rank + 1;
return 0;
}
void func_b(int arr[], int arr_len) {
qsort(arr, arr_len, sizeof(int), compare);
}
int func_c(int arr[], int n) {
return arr[n];
}
int solution(int scores[], int scores_len, int n) {
int score = //빈칸
//빈칸
int answer = //빈칸
return answer;
}
int main() {
int scores[4] = { 20, 60, 98, 59 };
int scores_len = 4;
int n = 3;
int ret = solution(scores, scores_len, n);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int compare(const void* a, const void* b) {
return (*(int*)b - *(int*)a);
}
int func_a(int scores[], int scores_len, int score) {
for (int rank = 0; rank < scores_len; rank++)
if (scores[rank] == score)
return rank + 1;
return 0;
}
void func_b(int arr[], int arr_len) {
qsort(arr, arr_len, sizeof(int), compare);
}
int func_c(int arr[], int n) {
return arr[n];
}
int solution(int scores[], int scores_len, int n) {
int score = func_c(scores, n);
func_b(scores, scores_len);
int answer = func_a(scores, scores_len, score);
return answer;
}
int main() {
int scores[4] = { 20, 60, 98, 59 };
int scores_len = 4;
int n = 3;
int ret = solution(scores, scores_len, n);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
결과
scores | scores_len | n | result |
[20,60,98,59] | 4 | 3 | 3 |
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 3차 4번_단어의 오타 수정하기 (C/C++) (0) | 2021.05.14 |
---|---|
[COS PRO 2급] 3차 2번_장학생 수 구하기 (C/C++) (0) | 2021.05.13 |
[COS PRO 2급] 2차 9번_투표에 대한 후보 찾기 (0) | 2021.05.12 |
[COS PRO 2급] 2차 7번_섭씨, 화씨 온도 바꾸기 (C/C++) (0) | 2021.05.11 |
[COS PRO 2급] 2차 8번_소수의 갯수 구하기 (C/C++) (0) | 2021.05.11 |
댓글
공지사항
최근에 올라온 글
TAG
- cospro기출
- C++
- 배열활용문제
- 1급
- 구름에듀 기출문제
- YBM기출
- groomedu
- 구름에듀
- 연습문제
- 알고리즘
- lv2
- Cos Pro
- 코딩테스트
- groom
- Java
- 배열
- C
- c언어
- 구름 기출문제
- 프로그래머스
- 코스프로
- COSPRO 2급
- c언어 기출문제
- 자바
- cospro기출문제
- CosPro
- programmers
- lv1
- YBM
- 기출문제
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함