Algorithm/BOJ
[BOJ] 7785번 회사에 있는 사람 - 미해결
Bueong_E
2023. 2. 12. 00:06
반응형
SMALL
문제
코드
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BOJ
{
internal class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
int N = int.Parse(sr.ReadLine());
Dictionary<string, int> dic = new Dictionary<string, int>();
for (int i = 0; i < N; i++)
{
string[] namesLogs = sr.ReadLine().Split();
if (namesLogs[1] == "enter")
{
dic.Add(namesLogs[0], 0);
}
else if (namesLogs[1] == "leave")
{
dic[namesLogs[0]] = 1;
}
}
List<string> list = new List<string>();
foreach (KeyValuePair<string, int> namelog in dic)
{
if (namelog.Value == 0 )
list.Add(namelog.Key);
}
List<string> newList = list.OrderByDescending(i => i).ToList();
foreach (string name in newList)
{
sw.WriteLine(name);
}
sr.Close();
sw.Close();
}
}
}
결과창
미해결 이유
계속 해서 런타임 에러가 뜨는 데 이유를 찾아보니 아래와 같은 이유를 의심해 보았다(결과가 많지 않아 일단 이정도의 정보만 찾을수 있었다.)
1. 같은 이름이 들어올 수 있어서 key값 충돌로 런타임 에러가 날수 있다.
2. 메서드에 제공된 인수 중 하나가 유효하지 않을 때 throw되는 예외이다.
좀더 이유를 찾아보고 안될시에는 카페에서 선생님 코드를 분석해서 앞으로 사용해야겠다 ( ㅠㅠ 런타임 에러를 한번도 해결한적이 없어서 답답하다)
반응형
LIST