Advertisement
simonradev

ArrayMatcher1.0

Mar 31st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. namespace ArrayMatcher
  2. {
  3.     using System;
  4.     using System.Text;
  5.  
  6.     public class ArrMatcher
  7.     {
  8.         public static StringBuilder result;
  9.  
  10.         public static void Main()
  11.         {
  12.             string[] arraysInfo = Console.ReadLine().Split('\\');
  13.  
  14.             string first = arraysInfo[0];
  15.             string second = arraysInfo[1];
  16.             string command = arraysInfo[2].ToLower();
  17.  
  18.             result = new StringBuilder();
  19.             switch (command)
  20.             {
  21.                 case "join":
  22.                     ExecuteTheCommand(first, second, false);
  23.                     break;
  24.  
  25.                 case "left exclude":
  26.                     ExecuteTheCommand(second, first, true);
  27.                     break;
  28.  
  29.                 case "right exclude":
  30.                     ExecuteTheCommand(first, second, true);
  31.                     break;
  32.                    
  33.                 default:
  34.                     break;
  35.             }
  36.  
  37.             SortTheResult();
  38.  
  39.             Console.WriteLine(result.ToString());
  40.         }
  41.  
  42.         private static void SortTheResult()
  43.         {
  44.             bool isSorted = false;
  45.             while (!isSorted)
  46.             {
  47.                 isSorted = true;
  48.  
  49.                 for (int currSymbol = 0; currSymbol < result.Length - 1; currSymbol++)
  50.                 {
  51.                     int asciiOfCurrSymbol = result[currSymbol];
  52.                     int asciiOfNextSymbol = result[currSymbol + 1];
  53.  
  54.                     if (asciiOfCurrSymbol > asciiOfNextSymbol)
  55.                     {
  56.                         char symbolHolder = result[currSymbol];
  57.                         result[currSymbol] = result[currSymbol + 1];
  58.                         result[currSymbol + 1] = symbolHolder;
  59.  
  60.                         isSorted = false;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.  
  66.         private static void ExecuteTheCommand(string toIterate, string toCheckForChars, bool exclude)
  67.         {
  68.             foreach (char symbol in toIterate)
  69.             {
  70.                 bool charIsContained = CheckIfCharIsContained(symbol, toCheckForChars);
  71.  
  72.                 if (exclude != charIsContained)
  73.                 {
  74.                     result.Append(symbol);
  75.                 }
  76.             }
  77.         }
  78.  
  79.         private static bool CheckIfCharIsContained(char toSearchFor, string toCheckForChars)
  80.         {
  81.             bool toReturn = false;
  82.  
  83.             foreach (char symbol in toCheckForChars)
  84.             {
  85.                 if (toSearchFor == symbol)
  86.                 {
  87.                     toReturn = true;
  88.  
  89.                     break;
  90.                 }
  91.             }
  92.  
  93.             return toReturn;
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement