Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Threading;
- public class Program
- {
- public static void Main()
- {
- string[] inp = Console.ReadLine().Split();
- int n = int.Parse(inp[0]);
- int m = int.Parse(inp[1]);
- var a1 = ReadArray(n);
- var a2 = ReadArray(m);
- var sw = new Stopwatch();
- sw.Start();
- var res = CountSameEntries()
- sw.Stop();
- Console.WriteLine(res);
- // получение прошедшего времени.
- TimeSpan ts = sw.Elapsed;
- // привидение времени в правильный формат и вывод его на экран.
- string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
- ts.Hours, ts.Minutes, ts.Seconds,
- ts.Milliseconds / 10);
- Console.WriteLine("Время выполнения: " + elapsedTime);
- // получение занимаемой памяти и вывод её на экран.
- var memory = (Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024).ToString() + " MB";
- Console.WriteLine("Объем занимаемой памяти (Мб): " + memory);
- Console.ReadKey();
- }
- static int CountSameEntries(int[] a, int[] b)
- {
- int counter = 0;
- int i = 0; int k = 0;
- while (i < a.Length && k < b.Length)
- {
- if (a[i] == b[k])
- {
- counter++; i++; k++;
- }
- else if (a[i] < b[k]) i++;
- else k++;
- }
- return counter;
- }
- static int[] ReadArray(int size)
- {
- var array = new int[size];
- for (int i = 0; i < size; i++)
- array[i] = int.Parse(Console.ReadLine());
- return array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement