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
'c# > 백준알고리즘' 카테고리의 다른 글
[백준 2004번 c#] 조합 0의 개수 (0) | 2022.10.05 |
---|---|
[백준 1676번 c#] 팩토리얼 0의 개수 (0) | 2022.10.05 |
[1934번 c#] 최소공배수 (0) | 2022.10.03 |
[백준 c#] 24060번 알고리즘 수업 - 병합 정렬 1 (1) | 2022.09.13 |
[백준 2798번 c#] 블랙잭 (0) | 2022.07.17 |