Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Practice
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var nums = Console.ReadLine().Split()
  15.                  .Select(int.Parse).ToList();
  16.  
  17.             var exepCount = 0;
  18.  
  19.             while (exepCount < 3)
  20.             {
  21.                 var input = Console.ReadLine().Split();
  22.                 var command = input[0];
  23.                 try
  24.                 {
  25.                     if (command == "Replace")
  26.                     {
  27.                         var index = int.Parse(input[1]);
  28.                         nums[index] = int.Parse(input[2]);
  29.                     }
  30.                     else if (command == "Print")
  31.                     {
  32.                         var index = int.Parse(input[1]);
  33.                         var endIndex = int.Parse(input[2]);
  34.                         Console.WriteLine
  35.                             (string.Join(", ", nums.GetRange(index, endIndex)));
  36.                     }
  37.                     else
  38.                     {
  39.                         var index = int.Parse(input[1]);
  40.                         Console.WriteLine(nums[index]);
  41.                     }
  42.                 }
  43.                 catch
  44.                 {
  45.                     if (input.Length > 2)
  46.                     {                        
  47.                         var check = 0;
  48.                         if (int.TryParse(input[1], out check) &&
  49.                             int.TryParse(input[2], out check))
  50.                         {
  51.                             Console.WriteLine("The index does not exist!");
  52.                         }
  53.                         else
  54.                             Console.WriteLine("The variable is not in the correct format!");
  55.                     }
  56.                     else
  57.                     {                        
  58.                         var check = 0;
  59.                         if (int.TryParse(input[1], out check))
  60.                         {
  61.                             Console.WriteLine("The index does not exist!");
  62.                         }
  63.                         else
  64.                             Console.WriteLine("The variable is not in the correct format!");
  65.                     }
  66.                     exepCount++;
  67.                 }
  68.             }
  69.             Console.WriteLine(string.Join(", ", nums));
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement