fbinnzhivko

04.001 Array Matcher

Mar 13th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Four
  6. {
  7.     static void Main()
  8.     {
  9.         string input = Console.ReadLine();
  10.  
  11.         string[] stringArray = input.Split(new Char[] { '\\' });
  12.  
  13.         string firstString = stringArray[0];
  14.         string secondString = stringArray[1];
  15.         string command = stringArray[2];
  16.  
  17.         //input is valid
  18.         List<char> result = new List<char>();
  19.  
  20.         //JOIN command
  21.         if (command == "join")
  22.         {
  23.             for (int first = 0; first < firstString.Length; first++)
  24.             {
  25.                 for (int second = 0; second < secondString.Length; second++)
  26.                 {
  27.                     if (firstString[first] == secondString[second])
  28.                     {
  29.                         result.Add(firstString[first]);
  30.                     }
  31.                 }
  32.             }
  33.  
  34.  
  35.  
  36.         }
  37.         //LEFT EXLUDE
  38.         else if (command == "left exclude")
  39.         {
  40.             for (int i = 0; i < secondString.Length; i++)
  41.             {
  42.                 result.Add(secondString[i]);
  43.             }
  44.  
  45.             for (int first = 0; first < secondString.Length; first++)
  46.             {
  47.                 for (int second = 0; second < firstString.Length; second++)
  48.                 {
  49.                     if (secondString[first] == firstString[second])
  50.                     {
  51.                         result.Remove(secondString[first]);
  52.                     }
  53.                 }
  54.             }
  55.  
  56.  
  57.         }
  58.         //RIGHT EXCLUDE
  59.         else if (command == "right exclude")
  60.         {
  61.             for (int i = 0; i < firstString.Length; i++)
  62.             {
  63.                 result.Add(firstString[i]);
  64.             }
  65.  
  66.             for (int first = 0; first < firstString.Length; first++)
  67.             {
  68.                 for (int second = 0; second < secondString.Length; second++)
  69.                 {
  70.                     if (firstString[first] == secondString[second])
  71.                     {
  72.                         result.Remove(firstString[first]);
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.  
  78.         //remove duplicates
  79.         List<char> finalResult = result.Distinct().ToList();
  80.         finalResult.Sort();
  81.  
  82.         for (int i = 0; i < finalResult.Count; i++)
  83.             {
  84.                 Console.Write(finalResult[i]);
  85.             }
  86.  
  87.     }
  88. }
Add Comment
Please, Sign In to add comment