Advertisement
mellowdeep

array matcher

Nov 9th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class ArrayMatcher
  6. {
  7.     static void Main()
  8.     {
  9.         string intput = Console.ReadLine();
  10.         string[] splitedInput = intput.Split('\\');
  11.  
  12.         var array1 = splitedInput[0];
  13.         var array2 = splitedInput[1];
  14.  
  15.         var newArray1 = array1.Except(array2);
  16.         string[] sortedArray1 = newArray1.Select(c => c.ToString()).ToArray();
  17.         Array.Sort(sortedArray1,StringComparer.Ordinal);
  18.  
  19.         var newArray2 = array2.Except(array1);
  20.         string[] sortedArray2 = newArray2.Select(c => c.ToString()).ToArray();
  21.         Array.Sort(sortedArray2,StringComparer.Ordinal);
  22.  
  23.         var bothArrays = array1 + array2;
  24.         var set = new HashSet<string>();
  25.         var duplicates = bothArrays
  26.                                 .GroupBy(i => i)
  27.                                 .Where(g => g.Count() > 1)
  28.                                 .Select(g => g.Key);
  29.  
  30.  
  31.         string[] sortedArrays = duplicates.Select(c => c.ToString()).ToArray();
  32.         Array.Sort(sortedArrays,StringComparer.Ordinal);
  33.  
  34.         if (splitedInput[2] == "join")
  35.         {
  36.             foreach (var ch in sortedArrays)
  37.             {
  38.                 Console.Write(ch);
  39.             }            
  40.             Console.WriteLine();
  41.         }
  42.         else if (splitedInput[2] == "right exclude")
  43.         {
  44.             foreach (var ch in sortedArray1)
  45.             {
  46.  
  47.                 Console.Write(ch);
  48.             }
  49.             Console.WriteLine();
  50.         }
  51.         else if (splitedInput[2] == "left exclude")
  52.         {
  53.             foreach (var ch in sortedArray2)
  54.             {
  55.                 Console.Write(ch);
  56.             }
  57.             Console.WriteLine();
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement