Advertisement
GerganaTsirkova

Anonymous Threat

Mar 11th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.80 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace _1.Anonymous_Treat
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> input = Console.ReadLine().Split(' ').ToList();
  14.             string[] command = Console.ReadLine().Split(' ').ToArray();
  15.             while (command[0] != "3:1")
  16.             {
  17.                 if (command[0] == "merge")
  18.                 {
  19.                     StringBuilder str = new StringBuilder();
  20.                     int startIndex = int.Parse(command[1]);
  21.                     int endIndex = int.Parse(command[2]);
  22.                     if (startIndex <= input.Count-1)
  23.                     {
  24.                         if (startIndex < 0)
  25.                         {
  26.                             startIndex = 0;
  27.                         }
  28.                         if (endIndex >= input.Count-1)
  29.                         {
  30.                             endIndex = input.Count - 1;
  31.                         }
  32.                         for (int i = startIndex; i <= endIndex; i++)
  33.                         {
  34.                             str.Append(input[i]);
  35.                         }
  36.                         for (int i = endIndex; i >= startIndex; i--)
  37.                         {
  38.                             input.RemoveAt(i);
  39.                         }
  40.                         string merged = str.ToString();
  41.                         input.Insert(startIndex, merged);
  42.                     }
  43.                 }
  44.                 else if (command[0] == "divide")
  45.                 {
  46.                     List<string> inner = new List<string>();
  47.                     int index = int.Parse(command[1]);
  48.                     int partition = int.Parse(command[2]);
  49.                     if(partition > 0 )
  50.                     {
  51.                         string strToDivide = input[index].ToString();
  52.                         int counter = 0;
  53.                         StringBuilder str = new StringBuilder();
  54.                         for (int i = 0; i < strToDivide.Length; i++)
  55.                         {
  56.                             if (counter == (int)strToDivide.Length / partition)
  57.                             {
  58.                                 if (i == strToDivide.Length - strToDivide.Length / partition)
  59.                                 {
  60.                                     inner.Add(str.ToString());
  61.                                     counter = 0;
  62.                                     str.Clear();
  63.                                     for (int j = i; j < strToDivide.Length; j++)
  64.                                     {
  65.                                         str.Append(strToDivide[j]);
  66.                                     }
  67.                                     inner.Add(str.ToString());
  68.                                     break;
  69.                                 }
  70.                                 else
  71.                                 {
  72.                                     inner.Add(str.ToString());
  73.                                     counter = 0;
  74.                                     str.Clear();
  75.                                     str.Append(strToDivide[i]);
  76.                                     counter++;
  77.                                 }
  78.                             }
  79.                             else
  80.                             {
  81.                                 str.Append(strToDivide[i]);
  82.                                 counter++;
  83.                             }
  84.                         }
  85.                         input.RemoveAt(index);
  86.                         input.InsertRange(index, inner);
  87.                     }
  88.                 }
  89.                 command = Console.ReadLine().Split(' ').ToArray();
  90.             }
  91.             Console.WriteLine(string.Join(" ", input));
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement