본문 바로가기
다이어리/내일배움 개발일지

게임개발캠프 - 팀과제(C) 4일차

by E.Clone 2024. 1. 30.

과정명 : 내일배움캠프 Unity 게임개발 3기

전체진행도 : 26일차

부분진행도 : Chapter3.2 - 4일차

작성일자 : 2024.01.29(월)

개발일지 목록 : 클릭


1. 진행중인 과정에 대해

팀 플젝을 마무리하고 개인 공부 시간을 가지기로 했다.

버그 픽스까지 마치고 피로함에 뻗어서 오늘은 넉다운 상태..

2. 오늘 학습에 대해

  • 코테 연습 한 문제

코딩테스트 연습 > 2023 KAKAO BLIND RECRUITMENT > 개인정보 수집 유효기간

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(string today, string[] terms, string[] privacies) {
        int[] answer = new int[] {};

        // 프로그래머스에서 메서드 사용하는 법 및 출력메시지 띄우는 법 확인
        // hello();

        // 예상 솔루션
        // 1. terms는 사전형 변수에 저장
        // 2. 년도에는 365, 달에는 28, 일에는 1의 가중치를 두어 각 정보와 today를 비교
        // 3. privacy가 같거나 작을 경우, result에 추가
        // 3-1. result는 값 갯수의 변동이 있으므로 리스트로 관리
        List<int> result = new List<int>();

        // 1. terms를 사전형 변수에 저장
        Dictionary<char,int> termsDict = new Dictionary<char,int>();
        foreach(string term in terms){
            // 검색: split 사용법(파이썬의 term.split())
            // -> 마찬가지로 term.Split(' '); 과 같이 사용 가능
            // 검색: 특정 인덱스 이후 모든 문자열을 사용하는법(파이썬의 term[2:])
            // -> term.Substring(2); 과 같이 사용 가능
            char key = term[0];
            int value = int.Parse(term.Substring(2));

            // Console.WriteLine($"{key}: {value}"); // 테스트 구문

            // 검색: 사전형에 요소 추가
            // -> termsDict.Add(key, value);

            termsDict.Add(key, value);
        }

        // 2. 년은 365, 달은 28, 일은 1의 가중치를 두어 각 정보와 today를 비교
        int today_value = 0;
        today_value = 
            int.Parse(today.Substring(0,4)) * 28*12 +
            int.Parse(today.Substring(5,2)) * 28 +
            int.Parse(today.Substring(8,2)) * 1
            ;
        Console.WriteLine($"Today value: {today_value}"); // 테스트 구문
        for(int i=0; i<privacies.Length; i++){
            string privacy = privacies[i];
            int limitDay_value = 
                int.Parse(privacy.Substring(0,4)) * 28*12 +
                int.Parse(privacy.Substring(5,2)) * 28 +
                int.Parse(privacy.Substring(8,2)) * 1 +
                termsDict[privacy[11]] * 28
                ;
            Console.WriteLine($"privacy index[{i+1}] value: {limitDay_value}"); // 테스트 구문
            // 3. privacy가 작을 경우, result에 추가
            if(limitDay_value <= today_value)
                result.Add(i+1);
        }

        answer = result.ToArray();

        return answer;
    }

    public void hello(){
        Console.WriteLine("Hello");
    }
}
  • 프로그래머스에서 메서드 사용하는 법 및 출력메시지 띄우는 법
  • 문자열에서 특정 문자를 기준으로 쪼개는 법 // .Split(' ')
  • 문자열 내에서 특정 인덱스 구간의 문자열을 떼어 사용하는 법 // .Substring(0,4)
  • 사전형에 요소 추가하기 // .Add(key, value)

3. 과제에 대해

  • 의견 모아 제출과 발표 마치기
반응형