오늘의 목표
아침 코드카타
언리얼 멀티플레이 5, 6강 수강
+ 추가목표
언리얼 마스터 지난주 강의 복습
코드카타
[문제] 완전탐색 모의고사
제 시간에 못 맞춤
[내 풀이]
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
// 1번 수포자 정답
int student1[5] = {1, 2, 3, 4, 5};
int student2[8] = {2, 1, 2, 3, 2, 4, 2, 5};
int student3[10] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
// 각 정답 비교
int student1_index = 0;
int student2_index = 0;
int student3_index = 0;
int student1_score = 0;
int student2_score = 0;
int student3_score = 0;
for (int answer : answers)
{
// 1번 수포자
if (student1[student1_index] == answer)
{
++student1_score;
student1_index = (student1_index + 1) % 5;
}
// 2번 수포자
if (student2[student2_index] == answer)
{
++student2_score;
student2_index = (student2_index + 1) % 8;
}
// 3번 수포자
if (student3[student3_index] == answer)
{
++student3_score;
student3_index = (student3_index + 1) % 10;
}
}
// 총 점수 저장
vector<int, int> student_scores =
{{1, student1_score}, {2, student2_score}, {3, student3_score}};
// sort
sort(student_scores.begin(), student_scores.end(), [](const auto& a, const auto& b){a[1] < b[1]});
int max_score = student_scores[0][1];
for(student_score : student_scores)
{
if (student_score[1] == max_score)
{
answer.push_back(student_score[0]);
}
}
return answer;
}
[개선된 코드]
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
// 수포자 정답 패턴
vector<int> student1 = {1, 2, 3, 4, 5};
vector<int> student2 = {2, 1, 2, 3, 2, 4, 2, 5};
vector<int> student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
vector<int> scores = {0, 0, 0};
for (int i = 0; i < answers.size(); ++i)
{
if (answers[i] == student1[i % student1.size()]) scores[0]++;
if (answers[i] == student2[i % student2.size()]) scores[1]++;
if (answers[i] == student3[i % student3.size()]) scores[2]++;
}
// 최댓값 저장
int max_score = *max_element(scores.begin(), scores.end());
// 최댓값과 같은 점수를 가진 학생 번호 저장
for (int i = 0; i < 3; ++i)
{
if(scores[i] == max_score)
{
answer.push_back(i + 1);
}
}
return answer;
}
개선점
- if 내부에서만 인덱스를 증가시키는 방식 폐지, for loop을 사용해서 i 인덱스를 각 학생의 정답 패턴 내 개수로 나누는(i % size) 방식으로 해결. 증가도 if문 내에서 시킴.
- max_element를 사용하여 점수 배열에서 가장 큰 값 구하기 (굳이 sort 쓸 필요 없음)
반성: c언어식으로 풀려고 해서 너무 돌아간 것 같다...
언리얼 멀티플레이 강의
개념정리
아직 SetOwner()가 진행되지 않은 PlayerCharacter-> SimulatedProxy로서 클라에 존재
SetOwner()실행 후 -> AutonomousProxy로서 존재. 패밀리에 포함되었기 때문

'Unreal5 공부 > TIL' 카테고리의 다른 글
| 2026/06/22 TIL (0) | 2026.06.22 |
|---|---|
| 2026/06/18 TIL (0) | 2026.06.18 |
| 2026/06/16 TIL (0) | 2026.06.16 |
| 2026/06/15 TIL (0) | 2026.06.15 |
| 2026/06/11 TIL (0) | 2026.06.11 |