[코테]/[GroomEdu]
[COS PRO 2급] 3차 1번_학생의 등수 구하기 (C/C++)
Sky_
2021. 5. 13. 22:50
주어진 코드
#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