Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ArrayMatcher
- {
- using System;
- using System.Text;
- public class ArrMatcher
- {
- public static StringBuilder result;
- public static void Main()
- {
- string[] arraysInfo = Console.ReadLine().Split('\\');
- string first = arraysInfo[0];
- string second = arraysInfo[1];
- string command = arraysInfo[2].ToLower();
- result = new StringBuilder();
- switch (command)
- {
- case "join":
- ExecuteTheCommand(first, second, false);
- break;
- case "left exclude":
- ExecuteTheCommand(second, first, true);
- break;
- case "right exclude":
- ExecuteTheCommand(first, second, true);
- break;
- default:
- break;
- }
- SortTheResult();
- Console.WriteLine(result.ToString());
- }
- private static void SortTheResult()
- {
- bool isSorted = false;
- while (!isSorted)
- {
- isSorted = true;
- for (int currSymbol = 0; currSymbol < result.Length - 1; currSymbol++)
- {
- int asciiOfCurrSymbol = result[currSymbol];
- int asciiOfNextSymbol = result[currSymbol + 1];
- if (asciiOfCurrSymbol > asciiOfNextSymbol)
- {
- char symbolHolder = result[currSymbol];
- result[currSymbol] = result[currSymbol + 1];
- result[currSymbol + 1] = symbolHolder;
- isSorted = false;
- }
- }
- }
- }
- private static void ExecuteTheCommand(string toIterate, string toCheckForChars, bool exclude)
- {
- int conditionToMatch = exclude ? 0 : 1;
- foreach (char symbol in toIterate)
- {
- int charIsContained = CheckIfCharIsContained(symbol, toCheckForChars);
- if (conditionToMatch == charIsContained)
- {
- result.Append(symbol);
- }
- }
- }
- /// <summary>
- /// Checks if a certain char is contained in a string
- /// </summary>
- /// <param name="toSearchFor">The char you want to check if it is in the string</param>
- /// <param name="toCheckForChars">The string you want to check for the char</param>
- /// <returns>0 if it is not contained and 1 if it is</returns>
- private static int CheckIfCharIsContained(char toSearchFor, string toCheckForChars)
- {
- int toReturn = 0;
- foreach (char symbol in toCheckForChars)
- {
- if (toSearchFor == symbol)
- {
- toReturn = 1;
- break;
- }
- }
- return toReturn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement