silvana1303

equal arrays / lists

Jun 2nd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5. using System.Text;
  6.  
  7. namespace exampreparation
  8. {
  9.     class exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<int> numbers1 = Console.ReadLine().Split().Select(int.Parse).ToList();
  15.             List<int> numbers2 = Console.ReadLine().Split().Select(int.Parse).ToList();
  16.  
  17.             if (numbers1.SequenceEqual(numbers2))
  18.             {
  19.                 int sum = numbers1.Sum();
  20.                 Console.WriteLine($"Arrays are identical. Sum: {sum}");
  21.             }
  22.             else
  23.             {
  24.                 for (int i = 0; i < numbers1.Count; i++)
  25.                 {
  26.                     if (numbers1[i] != numbers2[i])
  27.                     {
  28.                         Console.WriteLine($"Arrays are not identical. Found difference at {i} index");
  29.                         break;
  30.                     }
  31.                 }
  32.             }
  33.  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment