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
'백준 > C#' 카테고리의 다른 글
[C#]백준 28125: 2023 아주머학교 프로그래딩 정시머힌 (0) | 2023.07.19 |
---|---|
[C#]백준 28135: Since 1973 (0) | 2023.07.19 |
[C#]백준 1157번: 단어공부 (0) | 2023.07.19 |
[C#]백준 25206: 너의 평점은 (0) | 2023.07.19 |
[C#]백준 10988번: 팰린드롬인지 확인하기 (0) | 2023.07.19 |