Advertisement
Guest User

Tshko c#

a guest
Oct 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.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 AnonymousThreat
  8. {
  9.     class AnonymousThreat
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> input = Console.ReadLine().Split().ToList();
  14.             string command = string.Empty;
  15.  
  16.             while ((command = Console.ReadLine()) != "3:1")
  17.             {
  18.                 List<string> commandLine = command.Split().ToList();
  19.                 string operation = commandLine[0];
  20.                 int firstIndex = int.Parse(commandLine[1]);
  21.                 int secondIndex = int.Parse(commandLine[2]);
  22.  
  23.                 if (operation == "merge")
  24.                 {
  25.                     if (firstIndex < 0)
  26.                     {
  27.                         firstIndex = 0;
  28.                     }
  29.  
  30.                     if (secondIndex >= input.Count)
  31.                     {
  32.                         secondIndex = input.Count - 1;
  33.                     }
  34.  
  35.                     for (int i = firstIndex; i < secondIndex; i++)
  36.                     {
  37.                         input[firstIndex] = input[firstIndex] + input[firstIndex + 1];
  38.                         input.RemoveAt(firstIndex + 1);
  39.                     }
  40.                 }
  41.                 else if (operation == "divide")
  42.                 {
  43.                     int lengthOfAllParts = input[firstIndex].Length / secondIndex;
  44.                     int counter = 0;
  45.  
  46.                     for (int i = 0; i < secondIndex; i++)
  47.                     {
  48.                         string current = string.Empty;
  49.  
  50.                         if (i == secondIndex - 1)
  51.                         {
  52.                             for (int j = 0; j <= input[firstIndex].Length && counter < input[firstIndex].Length; j++)
  53.                             {
  54.                                 current += input[firstIndex][counter];
  55.                                 counter++;
  56.                             }
  57.                         }
  58.                         else
  59.                         {
  60.                             for (int j = 0; j < lengthOfAllParts; j++)
  61.                             {
  62.                                 current += input[firstIndex][counter];
  63.                                 counter++;
  64.                             }
  65.                         }
  66.                        
  67.                         input.Insert( firstIndex + i + 1,current);
  68.                     }
  69.  
  70.                     input.RemoveAt(firstIndex);
  71.                 }
  72.             }
  73.  
  74.             Console.WriteLine(string.Join(" ", input));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement