Advertisement
Guest User

01, Anonymous Threat

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 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 _01.Anonymous_Threat
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split(' ');
  14.             List<string> result = new List<string>(input);
  15.  
  16.             while (true)
  17.             {
  18.                 string inputLines = Console.ReadLine();
  19.                 if (inputLines == "3:1") { break; }
  20.  
  21.                 string[] splited = inputLines.Split(' ');
  22.                 string cmd = splited[0];
  23.  
  24.                 if (cmd == "merge")
  25.                 {
  26.                     int start = int.Parse(splited[1]);
  27.                     int end = int.Parse(splited[2]);
  28.  
  29.                     if (start < 0 || start >= result.Count) { start = 0; }
  30.                     if (end < 0 || end >= result.Count) { end = result.Count - 1; }
  31.  
  32.                     string merged = "";
  33.  
  34.                     for (int i = start; i <= end; i++)
  35.                     {
  36.                         merged += result[i];
  37.                     }
  38.                     if (start == 0) { result.RemoveRange(start, (end - start) + 1); }
  39.                     else { result.RemoveRange(start, (end - start) + 1); }
  40.                     result.Insert(start, merged);
  41.                 }
  42.                 else if (cmd == "divide")
  43.                 {
  44.                     int index = int.Parse(splited[1]);
  45.                     int partitions = int.Parse(splited[2]);
  46.                     string str = result[index];
  47.  
  48.                     int temp = str.Length / partitions;
  49.                     List<string> tempList = new List<string>();
  50.  
  51.                     if (temp % 2 == 0)
  52.                     {
  53.                         for (int i = 0; i < partitions; i++)
  54.                         {
  55.                             string tempStr = str.Substring(0, temp);
  56.                             str = str.Remove(0, temp);
  57.                             tempList.Add(tempStr);
  58.                         }
  59.                     }
  60.                     else
  61.                     {
  62.                         for (int i = 0; i < partitions - 1; i++)
  63.                         {
  64.                             string tempStr = str.Substring(0, temp);
  65.                             str = str.Remove(0, temp);
  66.                             tempList.Add(tempStr);
  67.                         }
  68.                         tempList.Add(str);
  69.                     }                
  70.                     result.InsertRange(index , tempList);
  71.                     result.RemoveAt(index+tempList.Count);
  72.                 }            
  73.             }
  74.             Console.WriteLine(string.Join(" ", result));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement