Advertisement
silvana1303

array modifier

Jul 6th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 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. using Microsoft.CSharp;
  7.  
  8.  
  9. namespace Order_By_Age
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  16.  
  17.             string[] command = Console.ReadLine().Split().ToArray();
  18.  
  19.             while (command[0] != "end")
  20.             {
  21.                 if (command[0] == "swap")
  22.                 {
  23.                    
  24.                     int index1 = int.Parse(command[1]);
  25.                     int index2 = int.Parse(command[2]);
  26.  
  27.                     if ((index1 >= 0 && index1 < numbers.Count) && index2 >= 0 && index2 < numbers.Count)
  28.                     {
  29.                         int temp = numbers[index1];
  30.                         numbers[index1] = numbers[index2];
  31.                         numbers[index2] = temp;
  32.                     }
  33.  
  34.                 }
  35.                 if (command[0] == "multiply")
  36.                 {
  37.                     int index1 = int.Parse(command[1]);
  38.                     int index2 = int.Parse(command[2]);
  39.  
  40.                     if ((index1 >= 0 && index1 < numbers.Count) && index2 >= 0 && index2 < numbers.Count)
  41.                     {
  42.                         numbers[index1] *= numbers[index2];
  43.                     }
  44.                 }
  45.                 if (command[0] == "decrease")
  46.                 {
  47.                     for (int i = 0; i < numbers.Count; i++)
  48.                     {
  49.                         numbers[i] -= 1;
  50.                     }
  51.                 }
  52.  
  53.                 command = Console.ReadLine().Split().ToArray();
  54.             }
  55.  
  56.             Console.WriteLine(string.Join(", ", numbers));
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement