Advertisement
DanDelatt

Mover

Sep 1st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 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.  
  7. namespace Mover
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Mover mover = new Mover();
  14.             Console.WriteLine("How many nubers do you want to move?");
  15.             string sdimension = Console.ReadLine();
  16.             mover.SetDimension(int.Parse(sdimension));
  17.             for (int i = 0; i < mover.GetDimension(); i++)
  18.             {
  19.                 Console.WriteLine("Please enter value of the number {0}", i + 1);
  20.                 string svalue = Console.ReadLine();
  21.                 mover.SetItemValue(i, int.Parse(svalue));
  22.  
  23.             }
  24.             Console.WriteLine("By how much do you want to move them");
  25.             string samount = Console.ReadLine();
  26.             mover.amount = int.Parse(samount);
  27.             mover.MoveU();
  28.             Console.WriteLine("--------------------------");
  29.             for (int i = 0; i < mover.GetDimension(); i++)
  30.             {
  31.                 Console.WriteLine(mover.GetItemValue(i));
  32.             }
  33.             Console.WriteLine("By Danila Dudkin https://vk.com/dandelay");
  34.             Console.ReadLine();
  35.         }
  36.     }
  37.  
  38.     class Mover
  39.     {
  40.         public int amount = 0;
  41.         int[] numbers;
  42.         int dimension;
  43.         public string direction;
  44.  
  45.         public void SetDimension(int dimension)
  46.         {
  47.             this.dimension = dimension;
  48.             Array.Resize(ref numbers, dimension);
  49.         }
  50.  
  51.         public int GetDimension()
  52.         {
  53.             return dimension;
  54.         }
  55.  
  56.         public void SetItemValue(int index, int value)
  57.         {
  58.             numbers[index] = value;
  59.         }
  60.  
  61.         public int GetItemValue(int index)
  62.         {
  63.             return numbers[index];
  64.         }
  65.  
  66.         public int[] GetArray()
  67.         {
  68.             return numbers;
  69.         }
  70.  
  71.         public void MoveU()
  72.         {
  73.  
  74.  
  75.             for (int i = 0; i < amount; i++)
  76.             {
  77.  
  78.  
  79.                 for (int j = 0; j < dimension - 1; j++)
  80.                 {
  81.                     int temporary;
  82.  
  83.                     temporary = numbers[j];
  84.                     numbers[j] = numbers[j + 1];
  85.                     numbers[j + 1] = temporary;
  86.                     if (j == dimension - 1)
  87.                     {
  88.                         temporary = numbers[dimension];
  89.                         numbers[dimension] = numbers[dimension - (dimension - 1)];
  90.                         numbers[dimension - (dimension - 1)] = temporary;
  91.                     }
  92.  
  93.                 }
  94.             }
  95.         }
  96.  
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement