Advertisement
JordanB

Anonymous Threat

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