Advertisement
Guest User

04. Array Matcher

a guest
Mar 30th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.  
  9.         string[] inputAsArray = Console.ReadLine().Split('\\');
  10.         string leftChars = inputAsArray[0];
  11.         string rightChars = inputAsArray[1];
  12.         string command = inputAsArray[2];
  13.  
  14.         string[] leftCharsArray = new string[leftChars.Length];
  15.  
  16.         for (int i = 0; i < leftChars.Length; i++)
  17.         {
  18.             leftCharsArray[i] = Convert.ToString(leftChars[i]);
  19.         }
  20.  
  21.         List<string> leftCharsList = new List<string>();
  22.  
  23.         for (int i = 0; i < leftCharsArray.Length; i++)
  24.         {
  25.             leftCharsList.Add(leftCharsArray[i]);
  26.         }
  27.  
  28.  
  29.         string[] rightCharsArray = new string[rightChars.Length];
  30.  
  31.         for (int i = 0; i < rightChars.Length; i++)
  32.         {
  33.             rightCharsArray[i] = Convert.ToString(rightChars[i]);
  34.         }
  35.             List<string> rightCharsList = new List<string>();
  36.  
  37.         for (int i = 0; i < rightCharsArray.Length; i++)
  38.         {
  39.             rightCharsList.Add(rightCharsArray[i]);
  40.         }
  41.  
  42.         List<string> outPut = new List<string>();
  43.  
  44.         switch (command)
  45.         {
  46.             case "join":
  47.                 foreach (var letter in leftCharsList)
  48.                 {
  49.                     if (rightCharsList.Contains(letter))
  50.                     {
  51.                         outPut.Add(letter);
  52.                     }
  53.                 }
  54.                 break;
  55.             case "right exclude":
  56.                 foreach (var letter in leftCharsList)
  57.                 {
  58.                     if (rightCharsList.Contains(letter))
  59.                     {
  60.                         continue;
  61.                     }
  62.                     else
  63.                     {
  64.                         outPut.Add(letter);
  65.                     }
  66.                 }
  67.                 break;
  68.             case "left exclude":
  69.                 foreach (var letter in rightCharsList)
  70.                 {
  71.                     if (leftCharsList.Contains(letter))
  72.                     {
  73.                         continue;
  74.                     }
  75.                     else
  76.                     {
  77.                         outPut.Add(letter);
  78.  
  79.                     }
  80.                 }
  81.                 break;
  82.         }
  83.         outPut.Sort();
  84.  
  85.         string output = "";
  86.         foreach (var item in outPut)
  87.         {
  88.             output = output + item;
  89.         }
  90.  
  91.         Console.WriteLine(output);
  92.         }
  93.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement