반응형
[ 문제 ]
숫자 카드는 정수 하나가 적혀져 있는 카드이다. 상근이는 숫자 카드 N개를 가지고 있다. 정수 M개가 주어졌을 때, 이 수가 적혀있는 숫자 카드를 상근이가 가지고 있는지 아닌지를 구하는 프로그램을 작성하시오.
[ 코드 ]
using System.Text;
StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
StringBuilder sb = new StringBuilder();
int n = int.Parse(sr.ReadLine());
string[] setNInput = sr.ReadLine().Split();
HashSet<int> setN = setNInput.Select(int.Parse).ToHashSet();
int m = int.Parse(sr.ReadLine());
string[] setMInput = sr.ReadLine().Split();
HashSet<int> setM = setMInput.Select(int.Parse).ToHashSet();
foreach (int i in setM)
{
bool check = setN.Contains(i);
sb.Append(check ? 1 : 0);
sb.Append(" ");
}
sw.Write(sb);
sw.Flush();
sw.Close();
sr.Close();
[ 실행화면 ]
문제링크: https://www.acmicpc.net/problem/10815
10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
반응형
'Language > C#' 카테고리의 다른 글
[C#] 백준 9012번 괄호 (0) | 2024.02.26 |
---|---|
[C#] 백준 1371번 가장 많은 글자 (0) | 2024.02.25 |
[C#] 백준 10773번 제로 (0) | 2024.02.24 |
[C#] 백준 2747번 피보나치 수 (0) | 2024.02.24 |
[C#] 백준 1075번 나누기 (0) | 2024.02.24 |