알고리즘/백준 BOJ
[ BOJ/C# ] 17219 비밀번호 찾기
왹져박사
2023. 9. 16. 23:46
https://www.acmicpc.net/problem/17219
17219번: 비밀번호 찾기
첫째 줄에 저장된 사이트 주소의 수 N(1 ≤ N ≤ 100,000)과 비밀번호를 찾으려는 사이트 주소의 수 M(1 ≤ M ≤ 100,000)이 주어진다. 두번째 줄부터 N개의 줄에 걸쳐 각 줄에 사이트 주소와 비밀번
www.acmicpc.net
Dictionary를 이용하는 문제이다. key는 중복 불가능하다는 점을 이용하여 비밀번호를 찾아준다.
using System;
using System.Text;
namespace B17219
{
class Program
{
static void Main()
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
StringBuilder sb = new StringBuilder();
int[] nm = Array.ConvertAll(sr.ReadLine().Split(' '), int.Parse);
Dictionary<string, string> dic = new Dictionary<string, string>();
string[] input;
for(int i = 0; i < nm[0]; i++)
{
input = sr.ReadLine().Split(' ');
dic.Add(input[0], input[1]);
}
for (int i = 0; i < nm[1]; i++) sb.Append(dic.GetValueOrDefault(sr.ReadLine()) + '\n');
sw.WriteLine(sb);
sr.Close();
sw.Flush();
sw.Close();
}
}
}