문제번호: 17219
문제명: 비밀번호 찾기
문제링크: https://www.acmicpc.net/problem/17219
문제내용과 예제 입/출력은 위 문제 링크에서 확인해 주시기 바랍니다.
이번 문제도 간단하게 풀 수 있었던 문제였습니다.
문제를 보자마자 사이트명과 비밀번호를 묶어 딕셔너리로 묶으면 탐색속도도 빨라지고 용이할 것 같아 딕셔너리를 사용하여 문제를 풀었습니다. 다음은 정답코드입니다.
public static void Main()
{
Dictionary<string, string> passwordDic = new();
int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int N = input[0];
int M = input[1];
for (int i = 0; i < N; i++)
{
string[] input_2 = Console.ReadLine().Split();
string siteLink = input_2[0];
string password = input_2[1];
passwordDic.Add(siteLink, password);
}
for(int i = 0; i < M; i++)
{
string site = Console.ReadLine();
Console.WriteLine(passwordDic[site]);
}
}
'알고리즘 풀이' 카테고리의 다른 글
| [C#] 백준 14916번 문제풀이 (0) | 2026.01.02 |
|---|---|
| [C#] 백준 2579번 문제풀이 (0) | 2026.01.02 |
| [C#] 백준 11047번 문제풀이 (0) | 2025.12.30 |
| [C#] 백준 11723번 문제풀이 (0) | 2025.12.29 |
| [C#] 백준 30802번 문제풀이 (0) | 2025.12.29 |