c#/백준알고리즘

[9375번 c#]패션왕 신해빈

Heeyeon Choi 2022. 10. 5. 09:23
728x90
728x90

- c# 에서는 dictionary의 키에 대한 값에 접근할 때, 배열처럼 접근할 수 있다.

- 만일, 같은 키값을 가진 값을 넣고 싶다면 dictionary<키, 리스트>로 넣을 수 있다.

- 해당 문제는 조합 문제로, 옷의 종류에 각각 몇개씩 있는지 확인 후, (ㅁ+1)* (o+1) -1 로 구하면 된다.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project2
{
    class Class1
    {
        static void Main(string[] args)
        {
            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput());
            StreamReader reader = new StreamReader(Console.OpenStandardInput());
            StringBuilder sb = new StringBuilder();


            //[1]입력
            //테스트 케이스
            int T = int.Parse(reader.ReadLine());

            for (int j = 0; j < T; j++)
            {
                //아이템 수
                int item = int.Parse(reader.ReadLine());
                Dictionary<string, int> dic = new Dictionary<string, int>();

                for (int i = 0; i < item; i++)
                {
                    string[] a = reader.ReadLine().Split();

                    //옷 종류
                    string c = a[1];

                    if (dic.ContainsKey(c))
                    {
                        dic[c]++;
                    }
                    else
                    {
                        dic.Add(c, 1);  
                    }
                   
                }
                //[2]process
                int ans = 1;

                foreach(int val in dic.Values)
                {
                    ans *= (val+1);
                }

                writer.WriteLine(ans-1);


            }


            writer.Close();
            reader.Close();


        }

  


    }


}

 

728x90