완주하지 못한 선수
Algorithm 2021. 1. 7. 23:59반응형
programmers.co.kr/learn/courses/30/lessons/42576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string[] participant = { "john", "ed", "joe", "rick", "john" };
string[] completed = { "john", "ed", "joe", "john" };
Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (var name in completed) {
if (!dic.ContainsKey(name)) {
dic.Add(name, 1);
}
}
string answer = "";
foreach (var name in participant)
{
if (dic.ContainsKey(name))
{
dic[name] -= 1;
}
else {
answer = name;
break;
}
if (dic[name] < 0)
{
answer = name;
break;
}
}
Console.WriteLine("------------------->" + answer);
}
}
}
반응형
'Algorithm' 카테고리의 다른 글
Simple Binary Tree (0) | 2021.03.05 |
---|---|
LCRSTree (0) | 2021.03.04 |
C# program to implement Binary Search Tree (0) | 2020.10.23 |
실전 알고리즘 강좌 바킹독 (0) | 2020.10.23 |
선택정렬 (Selection Sort) C# (0) | 2020.10.23 |