Advertisement
gospod1978

List-Ex/Anonymous Threat

Oct 23rd, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp10
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> input = Console.ReadLine().Split().ToList();
  14.  
  15.             while (true)
  16.             {
  17.                 string[] commands = Console.ReadLine().Split();
  18.                 string command = commands[0];
  19.  
  20.                 if (command == "3:1")
  21.                 {
  22.                     break;
  23.                 }
  24.  
  25.                 int startIndex = int.Parse(commands[1]);
  26.                 int endIndex = int.Parse(commands[2]);
  27.                 string concatWord = string.Empty;
  28.  
  29.                 if (endIndex > input.Count - 1 || endIndex < 0)
  30.                 {
  31.                     endIndex = input.Count - 1;
  32.                 }
  33.  
  34.                 if (startIndex < 0 || startIndex > input.Count)
  35.                 {
  36.                     startIndex = 0;
  37.                 }
  38.  
  39.                 if (command == "merge")
  40.                 {
  41.                     for (int i = startIndex; i <= endIndex; i++)
  42.                     {
  43.                         concatWord += input[i];
  44.                     }
  45.  
  46.                     input.RemoveRange(startIndex, endIndex - startIndex + 1);
  47.                     input.Insert(startIndex, concatWord);
  48.  
  49.                 }
  50.                 else if (command == "divide")
  51.                 {
  52.                     List<string> divided = new List<string>();
  53.  
  54.                     int divide = int.Parse(commands[2]);
  55.  
  56.                     string word = input[startIndex];
  57.  
  58.                     input.RemoveAt(startIndex);
  59.  
  60.                     int parts = word.Length / divide;
  61.  
  62.                     for (int i = 0; i < divide; i++)
  63.                     {
  64.                         if (i == divide - 1)
  65.                         {
  66.                             divided.Add(word.Substring(i * parts));
  67.                         }
  68.                         else
  69.                         {
  70.                             divided.Add(word.Substring(i * parts, parts));
  71.                         }
  72.                     }
  73.                     input.InsertRange(startIndex, divided);
  74.                 }
  75.  
  76.             }
  77.  
  78.             Console.WriteLine(string.Join(" ", input));
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement