Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

동구의_C# & Unity_개발일지

2024.03.12 내일배움캠프 53일차 TIL_Unity (최종 프로젝트, 알고리즘, 기술 면접) 본문

최종 프로젝트

2024.03.12 내일배움캠프 53일차 TIL_Unity (최종 프로젝트, 알고리즘, 기술 면접)

mongle_0l 2024. 3. 12. 10:54

알고리즘 코드카타 37일차

크기가 작은 부분문자열

문제 설명
숫자로 이루어진 문자열 t와 p가 주어질 때, t에서 p와 길이가 같은 부분문자열 중에서, 이 부분문자열이 나타내는 수가 p가 나타내는 수보다 작거나 같은 것이 나오는 횟수를 return하는 함수 solution을 완성하세요.예를 들어, t="3141592"이고 p="271" 인 경우, t의 길이가 3인 부분 문자열은 314, 141, 415, 159, 592입니다. 이 문자열이 나타내는 수 중 271보다 작거나 같은 수는 141, 159 2개 입니다.
using System;

public class Solution {
    public int solution(string t, string p) {
        int answer = 0;
        long num = 0;
        for(int i = 0; i < t.Length - p.Length + 1; i++)
        {
            num = long.Parse(t.Substring(i, p.Length));
            if(num <= long.Parse(p)) { answer++; }
        }
        return answer;
    }
}


기술면접 연습하기 5일차

가비지 컬렉터에 대해 설명해주세요
가비지 컬렉터(Garbage Collector)는 프로그래밍 언어나 런타임 환경에서 동적으로 할당된 메모리 중에서 더 이상 사용되지 않는 객체들을 자동으로 파악하고 제거하는 기능을 말한다.

이는 메모리 누수(memory leak)와 같은 문제를 방지하여 프로그램의 안정성과 성능을 향상시키는 데 중요한 역할을 한다.

최종 프로젝트

using UnityEngine;
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using System.IO;
using System.Collections;

[System.Serializable]
public class Quest
{
    public int ID;
    public string Name;
    public int Gold;
    public int Exp;
    public string Description;
}

public class QuestInstance
{
    int no;
    public Quest quest;
}

[System.Serializable]
public class questDatabase
{
    public string questDataPath;
    public List<Quest> QuestInfos;
    public Dictionary<int, Quest> questDic = new();


    void Start()
    {
        LoadQuestData();
    }

    void LoadQuestData()
    {
        // JSON 파일 읽기
        string json;
        using (StreamReader reader = new StreamReader(questDataPath))
        {
            json = reader.ReadToEnd();
        }

        // JSON 파싱하여 딕셔너리에 저장
        List<Quest> questList = JsonConvert.DeserializeObject<List<Quest>>(json);
        questDic = new Dictionary<int, Quest>();

        // 각 퀘스트를 딕셔너리에 추가
        foreach (Quest quest in questList)
        {
            questDic.Add(quest.ID, quest);
        }
    }
}
퀘스트 데이터을 엑셀 JSON으로 저장하였다.