오늘은 코드카타 2개 제출과 함께 1-5강에서 1-7강까지 한번씩 듣고 5강까지 따라해보았다.
두 정수 사이의 합
접근 방법은 알았지만, 힌트를 검색해보고서 int start = min(a, b);와 int end = max(a, b); 를 사용하였다.
#include <string>
#include <vector>
using namespace std;
long long solution(int a, int b) {
long long answer = 0;
int start = min(a, b);
int end = max(a, b);
for(int i = start; i <= end; i++)
{
answer += i;
}
return answer;
}
콜라츠 추측
조건이 만족될때까지 계속 반복이다보니 반복문 중 While문으로 접근하였고, While(1)과 조건형 While중에 후자를 선택하였다.
#include <string>
#include <vector>
using namespace std;
int solution(int num) {
long long n = num;
int answer = 0;
if (n == 1) return 0;
while(n != 1 && answer < 500)
{
if(n % 2 == 0)
{
n = n / 2;
}
else
{
n = n * 3 + 1;
}
answer++;
}
if (n == 1) return answer;
return -1;
}
그리고 따라해 본 건 1-5강까지였기 때문에 내용 정리는 5강까지.
현재까지 한 진도는 여기에.
더보기
더보기
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Item.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogSparta, Warning, All);
UCLASS()
class SPARTAPROJECT_API AItem : public AActor
{
GENERATED_BODY()
public:
AItem();
protected:
USceneComponent* SceneRoot;
UStaticMeshComponent* StaticMeshComp;
virtual void PostInitializeComponents() override;
virtual void BeginPlay() override;
virtual void Tick(float Deltatime) override;
virtual void Destroyed() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
};
#include "Item.h"
DEFINE_LOG_CATEGORY(LogSparta);
// Sets default values
AItem::AItem()
{
PrimaryActorTick.bCanEverTick = true;
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
SceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
SetRootComponent(SceneRoot);
StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
StaticMeshComp->SetupAttachment(SceneRoot);
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset(TEXT("/Game/Resources/Props/SM_Chair.SM_Chair"));
if (MeshAsset.Succeeded())
{
StaticMeshComp->SetStaticMesh(MeshAsset.Object);
}
static ConstructorHelpers::FObjectFinder<UMaterial>MaterialAsset(TEXT("/Game/Resources/Materials/M_Metal_Gold.M_Metal_Gold"));
if (MaterialAsset.Succeeded())
{
StaticMeshComp->SetMaterial(0, MaterialAsset.Object);
}
UE_LOG(LogSparta, Warning, TEXT("%s Constructor"), *GetName());
}
void AItem::PostInitializeComponents()
{
Super::PostInitializeComponents();
UE_LOG(LogSparta, Warning, TEXT("%s PostInitializeComponents"), *GetName());
}
void AItem::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("%s BeginPlay"), *GetName());
}
void AItem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AItem::Destroyed()
{
UE_LOG(LogTemp, Warning, TEXT("%s Destroyed"), *GetName());
Super::Destroyed();
}
void AItem::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
UE_LOG(LogSparta, Warning, TEXT("%s EndPlay"), *GetName());
Super::EndPlay(EndPlayReason);
}
'TIL' 카테고리의 다른 글
| 1/16일자 TIL (0) | 2026.01.16 |
|---|---|
| 1/15일자 TIL (0) | 2026.01.15 |
| 1/13일자 TIL (0) | 2026.01.13 |
| 1/12일자 TIL (0) | 2026.01.12 |
| 1/09일자 TIL (0) | 2026.01.09 |