Advertisement
braveheart1989

ArrayModifier

Apr 24th, 2016
205
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 System.Numerics;
  7.  
  8. namespace _04.ArrayModifier
  9. {
  10.     class ArrayModifier
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             long[] array = Console.ReadLine().ToLower().Split(' ').Select(long.Parse).ToArray();
  15.  
  16.             string[] input = Console.ReadLine().Split();
  17.  
  18.             while (input[0] != "end")
  19.             {
  20.                 switch (input[0])
  21.                 {
  22.                     case "swap":
  23.                         SwapInts(array, long.Parse(input[1]), long.Parse(input[2]));
  24.                         break;
  25.                     case "multiply":
  26.                         MultiplyInt(array, long.Parse(input[1]), long.Parse(input[2]));
  27.                         break;
  28.                     case "decrease":
  29.                         DecreaseInt(array);
  30.                         break;
  31.                 }
  32.  
  33.                 input = Console.ReadLine().ToLower().Split();
  34.             }
  35.             Console.WriteLine(string.Join(", ", array));
  36.         }
  37.  
  38.         static long[] MultiplyInt(long[] array, long pos1, long pos2)
  39.         {
  40.             array[pos1] = array[pos1] * array[pos2];
  41.             return array;
  42.         }
  43.  
  44.         //23 -84 321 87 42 90 -123
  45.  
  46.         static long[] DecreaseInt(long[] array)
  47.         {
  48.             for (int i = 0; i < array.Length; i++)
  49.             {
  50.                 array[i] -= 1;
  51.             }
  52.             return array;
  53.         }
  54.  
  55.         static long[] SwapInts(long[] array, long position1, long position2)
  56.         {
  57.             long temp = array[position1];
  58.             array[position1] = array[position2];
  59.             array[position2] = temp;
  60.             return array;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement