본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 1920 수 찾기

by 왹져박사 2023. 9. 3.
728x90

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

 

1920번: 수 찾기

첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들

www.acmicpc.net

list.Contains로 list에 포함되었는지 찾아준다. 

using System;
using System.Text;

namespace B1920
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(sr.ReadLine());
            string[] str = sr.ReadLine().Split(' ');

            List<int> listA = new List<int>();
            for (int i = 0; i < n; i++)
            {
                listA.Add(int.Parse(str[i]));
            }
            listA.Sort();

            int m = int.Parse(sr.ReadLine());
            str = sr.ReadLine().Split(' ');

            for(int i = 0; i < m; i++)
            {
                if (listA.Contains(int.Parse(str[i]))) sb.AppendLine("1");
                else sb.AppendLine("0");
            }
            sw.WriteLine(sb);

            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 1874 스택 수열  (0) 2023.09.05
[ BOJ/C# ] 2164 카드2  (0) 2023.09.05
[ BOJ/C# ] 1676 팩토리얼 0의 개수  (0) 2023.09.03
[ BOJ/C# ] 1546 평균  (0) 2023.09.01
[ BOJ/C# ] 2869 달팽이는 올라가고 싶다  (0) 2023.09.01