Advertisement
AlexVanchov

1

Apr 4th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace Final_Exam_April_04
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             var text = input;
  14.  
  15.             input = Console.ReadLine();
  16.             while (input != "Done")
  17.             {
  18.                 string[] arr = input.Split(" ").ToArray();
  19.                 string newCommnad = arr[0];
  20.                 if (newCommnad == "TakeOdd")
  21.                 {
  22.                     StringBuilder sb = new StringBuilder();
  23.                     for (int i = 0; i < text.Length; i++)
  24.                     {
  25.                         if (!(i % 2 == 0))
  26.                         {
  27.                             sb.Append(text[i]);
  28.                         }
  29.                     }
  30.                     var result = sb.ToString();
  31.                     Console.WriteLine(result);
  32.                 }
  33.                 else if (newCommnad == "Cut")
  34.                 {
  35.                     int startIndex = int.Parse(arr[1]);
  36.                     int endIndex = int.Parse(arr[2]);
  37.                     if (startIndex >= 0 && endIndex < text.Length)
  38.                     {
  39.                         int length = endIndex - startIndex + 1;
  40.  
  41.                         text = text.Remove(startIndex, length);
  42.  
  43.                         Console.WriteLine(text);
  44.                     }
  45.                 }
  46.  
  47.                 input = Console.ReadLine();
  48.             }
  49.  
  50.  
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement