SMALL

https://www.acmicpc.net/problem/25192

 

25192번: 인사성 밝은 곰곰이

첫번째 새로운 사람이 들어온 뒤  pjshwa, chansol, chogahui05은 모두 곰곰티콘으로 인사했다. 두번째 새로운 사람이 들어온 뒤  pjshwa와 chansol은 다시 곰곰티콘으로 인사했다.

www.acmicpc.net


  • 문제


  • 문제풀이

HashSet을 설정해서 key값을 통해 기존에 있던 아이디인지 확인이 가능하다.


  • 코드 1
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;


class Program
{
    
    static void Main(string[] args)
    {
        int n = int.Parse(ReadLine());
        HashSet<string> ans = new HashSet<string>();
        int cnt = 0;
        for (int i = 0; i < n; i++)
        {
            string str = ReadLine();
            if (str == "ENTER")
            {
                cnt += ans.Count();
                ans.Clear();
            }
            else
            {
                if (!ans.Contains(str))
                {
                    ans.Add(str);
                    
                }
            }
        }
        cnt += ans.Count();
        WriteLine(cnt);

    }
    
}

  • 후기

HashSet은 처음 써본다

LIST

+ Recent posts