Advertisement
GrandtherAzaMarks

Мутанты

Feb 9th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp17
  8. {
  9.     class Program
  10.     {
  11.         static int BinSearch(int[] N, int key)
  12.         {
  13.             int l = -1, r = N.Length, m = 0;
  14.             int counter = 0;
  15.             while (l < r - 1)
  16.             {
  17.                 m = (l + r) / 2;
  18.                 if (N[m] < key)
  19.                     l = m;
  20.                 else
  21.                     r = m;
  22.             }
  23.  
  24.             if (r == N.Length)
  25.                 return -1;
  26.             else if (N[r] == key)
  27.             {
  28.                 N[r] = -1;
  29.                 counter++;
  30.             }
  31.             else
  32.                 return -1;
  33.         }
  34.  
  35.         static void Main(string[] args)
  36.         {
  37.             int n = Convert.ToInt32(Console.ReadLine());
  38.             int[] N = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
  39.             int m = Convert.ToInt32(Console.ReadLine());
  40.             int[] M = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
  41.  
  42.             for (int i = 0; i < m; i++)
  43.                 BinSearch(N, M[i]);
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement