Menu
Coddy logo textTech

Recap - HashMap

Coddy C# 여정의 논리 및 흐름 섹션에 포함된 레슨 — 66개 중 51번째.

challenge icon

챌린지

쉬움

ProcessDictionary라는 메서드를 생성하세요. 이 메서드는 Dictionary<string, int>와 작업 배열을 매개변수로 받습니다. 이 메서드는 다음 작업을 수행해야 합니다:

  1. 작업이 "GET key"인 경우, 해당 키의 값을 출력하거나 키가 존재하지 않으면 "Not found"를 출력하세요
  2. 작업이 "CHECK key"인 경우, 키가 존재하면 "Exists"를 출력하고, 그렇지 않으면 "Not found"를 출력하세요
  3. 작업이 "MODIFY key value"인 경우, 다음을 수행하세요:
    • 키가 존재하고 제공된 값과 동일한 경우, 그 값을 1 증가시키세요
    • 키가 존재하지만 값이 다른 경우, 키를 제거하세요
    • 키가 존재하지 않으면, 제공된 값으로 키를 추가하세요

모든 작업을 처리한 후 업데이트된 Dictionary를 반환하세요.

직접 해보기

using System;
using System.Collections.Generic;

class Program
{
    public static Dictionary<string, int> ProcessDictionary(Dictionary<string, int> data, string[] operations)
    {
        // 여기에 코드를 작성하세요
    }

    static void Main(string[] args)
    {
        // 일부 데이터로 딕셔너리 초기화
        Dictionary<string, int> data = new Dictionary<string, int>
        {
            { "Apple", 10 },
            { "Banana", 5 },
            { "Orange", 7 }
        };

        // 샘플 작업
        string[] operations = new string[] 
        {
            "GET Apple",
            "CHECK Mango", 
            "MODIFY Banana 5",
            "MODIFY Orange 8",
            "MODIFY Mango 3"
        };

        Dictionary<string, int> result = ProcessDictionary(data, operations);
        
        // 결과 표시
        Console.WriteLine("Updated Dictionary:");
        foreach (var item in result)
        {
            Console.WriteLine($"{item.Key}: {item.Value}");
        }
    }
}

논리 및 흐름의 모든 레슨