coasterka

AreTwoArraysEqual

Mar 9th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             Console.WriteLine("Input elements of first array.");
  4.             string inputArrayOne = Console.ReadLine();
  5.             Console.WriteLine("Input elements of second array.");
  6.             string inputArrayTwo = Console.ReadLine();
  7.  
  8.             string[] inputOne = inputArrayOne.Split(' ');
  9.             string[] inputTwo = inputArrayTwo.Split(' ');
  10.  
  11.             int[] arr1 = new int[inputOne.Length];
  12.             for (int i = 0; i < inputOne.Length; i++)
  13.             {
  14.                 arr1[i] = int.Parse(inputOne[i]);
  15.             }
  16.             int[] arr2 = new int[inputTwo.Length];
  17.             for (int i = 0; i < inputTwo.Length; i++)
  18.             {
  19.                 arr2[i] = int.Parse(inputTwo[i]);
  20.             }
  21.  
  22.             int counterOfEqualElements = 0;
  23.             if (arr1.Length != arr2.Length)
  24.             {
  25.                 Console.WriteLine("False");
  26.             }
  27.             else
  28.             {
  29.                 for (int i = 0; i < arr1.Length; i++)
  30.                 {
  31.                     if (arr1[i] == arr2[i])
  32.                     {
  33.                         counterOfEqualElements++;
  34.                     }
  35.                 }
  36.                 if (counterOfEqualElements == arr1.Length)
  37.                 {
  38.                     Console.WriteLine("True");
  39.                 }
  40.                 else
  41.                 {
  42.                     Console.WriteLine("False");
  43.                 }
  44.             }
  45.         }
Advertisement
Add Comment
Please, Sign In to add comment