Unreal5 공부/TIL

2026/06/16 TIL

anna59 2026. 6. 16. 21:36

 

오늘의 목표

아침 코드카타

언리얼 멀티플레이 강의 수강 (5강, 6강)

언리얼 마스터 강의 복습 

 

+ 추가 목표

언리얼 기초 강의 수강

기획 강의 수강


 

코드카타

[문제] 과일 장수

 

시간 내에 못 풂...

 

[내 풀이]

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int compare_descend(const int* a, const int* b)
{
    return *b - *a;
}

// score_len은 배열 score의 길이입니다.
int solution(int k, int m, int score[], size_t score_len) {
    int answer = 0;
    
    // 사과 박스 점수 내림차순 정렬
    qsort(score, score_len, sizeof(int), compare_descend);
    
    // 만들 수 있는 사과 박스의 총 개수
    int box_max = (int)score_len / m;
    // 박스 내의 사과 개수
    int apple_count = 0;
    // 현재 채워진 박스 개수
    int box_count = 0;
    
    // 전체 사과 점수 array index
    int score_index = 0;
    // 박스 내에서 가장 낮은 점수
    int apple_minscore = score[0];
    while (box_count < box_max)
    {
        int applebox[m];
        for(; score_index < score_len; ++score_index)
        {
           applebox[apple_count] = score[score_index];
            if (apple_minscore > score[score_index])
            {
                apple_minscore = score[score_index];
            }
        }
        answer += apple_minscore * m;
        ++box_count;
    }
    
    
    return answer;
}

 

 

전체 스코어를 내림차순으로 정렬한 뒤 차례대로 m개씩 묶어 저장하고 최솟값 * m을 통해 저장하고자 했다.

 

개선점:

이미 숫자가 정렬된 상태이므로 굳이 최솟값을 열심히 찾을 필요가 없음.

m번째 사과의 점수가 무조건 해당 박스의 최하점

 

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int compare_descend(const void* a, const void* b)
{
    return *(int*)b - *(int*)a;
}

// score_len은 배열 score의 길이입니다.
int solution(int k, int m, int score[], size_t score_len) {
    int answer = 0;
    
    // 사과 박스 점수 내림차순 정렬
    qsort(score, score_len, sizeof(int), compare_descend);
    
    for (int i = m - 1; i < (int) score_len; i+=m)
    {
        answer += score[i] * m;
    }
    
    
    return answer;
}

 

정렬한 뒤 m번째 사과만 골라서 *m을 한 뒤 더하면 답이 나온다.

굉장히 간단하다...

 

 

언리얼 멀티플레이 강의

 

개념 정리

 

서버에서 ClientConnection을 살펴보고 싶다면

- AGameModeBase::PostLogin() 함수

클라이언트에서 ServerConnection을 살펴보고 싶다면

- APlayerController::PostNetInit()

서버의 액터가 모두 복제된 후에 호출되는 함수