Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp17
- {
- class Program
- {
- static int BinSearch(int[] N, int key)
- {
- int l = -1, r = N.Length, m = 0;
- int counter = 0;
- while (l < r - 1)
- {
- m = (l + r) / 2;
- if (N[m] < key)
- l = m;
- else
- r = m;
- }
- if (r == N.Length)
- return -1;
- else if (N[r] == key)
- {
- N[r] = -1;
- counter++;
- }
- else
- return -1;
- }
- static void Main(string[] args)
- {
- int n = Convert.ToInt32(Console.ReadLine());
- int[] N = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
- int m = Convert.ToInt32(Console.ReadLine());
- int[] M = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
- for (int i = 0; i < m; i++)
- BinSearch(N, M[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement