TheBulgarianWolf

Anonymous Threat

Dec 18th, 2020
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Anonymous_Thread
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your input here: ");
  11.             string line = Console.ReadLine();
  12.             string[] lineArr = line.Split(", ");
  13.             List<string> lineList = new List<string>(lineArr);
  14.             Console.WriteLine("There are 3 commands you can use: ");
  15.             Console.WriteLine("1. merge {startIndex} {endIndex} - used to merge all elements from the start index to last index.");
  16.             Console.WriteLine("2. divide {index} {partitions} - used to divide a selected element to given number of pieces.");
  17.             Console.WriteLine("3. 3:1 - used to print the results,after that the program ends.");
  18.             string command;
  19.             while ((command = Console.ReadLine()) != "3:1")
  20.             {
  21.                 string[] commandTokens = command.Split();
  22.                 string firstToken = commandTokens[0];
  23.                 int secondToken = int.Parse(commandTokens[1]);
  24.                 int thirdToken = int.Parse(commandTokens[2]);
  25.                 //merge operation
  26.                 if (firstToken == "merge")
  27.                 {
  28.                     if (secondToken < 0)
  29.                     {
  30.                         secondToken = 0;
  31.                     }
  32.                     if (thirdToken > lineArr.Length)
  33.                     {
  34.                         thirdToken = lineArr.Length;
  35.                     }
  36.                     string concatenatedString = "";
  37.                     for (int i = secondToken; i <= thirdToken; i++)
  38.                     {
  39.                         concatenatedString += lineList[i];
  40.  
  41.                     }
  42.                     for (int l = secondToken; l <= thirdToken; l++)
  43.                     {
  44.                         lineList.RemoveAt(secondToken);
  45.  
  46.                     }
  47.  
  48.                     lineList.Insert(0, concatenatedString);
  49.  
  50.  
  51.                 }
  52.                 else if (firstToken == "divide")
  53.                 {
  54.                     int index = secondToken;
  55.                     int parts = thirdToken;
  56.                     string selectedItem = lineList[index];
  57.                     int stringSize = selectedItem.Length;
  58.                     int partSize = stringSize / parts;
  59.                     lineList.RemoveAt(index);
  60.                     int wordIndex = 0;
  61.                     if (stringSize % parts == 0)
  62.                     {
  63.  
  64.  
  65.                         for (int part = 0; part < parts; part++)
  66.                         {
  67.                             int ind = 0;
  68.                             for (int m = ind; m < partSize; m++)
  69.                             {
  70.                                 string word = "";
  71.                                 for (int s = wordIndex; s < wordIndex + partSize; s++)
  72.                                 {
  73.                                     word += selectedItem[wordIndex];
  74.  
  75.                                 }
  76.                                 wordIndex++;
  77.                                 lineList.Insert(index + m, word);
  78.                             }
  79.                         }
  80.  
  81.  
  82.                     }
  83.                     else
  84.                     {
  85.                         for (int part = 0; part < parts - 1; part++)
  86.                         {
  87.                             int ind = 0;
  88.                             for (int m = ind; m < partSize; m++)
  89.                             {
  90.                                 string word = "";
  91.                                 for (int s = wordIndex; s < wordIndex + partSize; s++)
  92.                                 {
  93.                                     word += selectedItem[wordIndex];
  94.  
  95.                                 }
  96.                                 wordIndex++;
  97.                                 lineList.Insert(index + m, word);
  98.                             }
  99.                         }
  100.                         string lastWord = "";
  101.                         for (int s = wordIndex; s < wordIndex + partSize + 1; s++)
  102.                         {
  103.                             lastWord += selectedItem[wordIndex];
  104.  
  105.                         }
  106.                         wordIndex++;
  107.                         lineList.Insert(index + parts - 1, lastWord);
  108.                     }
  109.                 }
  110.             }
  111.  
  112.             foreach (string item in lineList)
  113.             {
  114.                 Console.Write(item + " ");
  115.             }
  116.         }
  117.     }
  118. }
  119.  
Add Comment
Please, Sign In to add comment