Advertisement
EmoRz

Donald_Rainer

May 3rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace p02
  6. {
  7.     class Program
  8.     {
  9.         //Rainer
  10.         static void Main(string[] args)
  11.         {
  12.             int[] sequence = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.             int[] field = new int[sequence.Length-1];
  14.             int[] initial = new int[sequence.Length - 1];
  15.             int index = sequence[sequence.Length-1];
  16.             var steps = 0;
  17.             for (int i = 0; i < field.Length; i++)
  18.             {
  19.                 field[i] = sequence[i];
  20.                 initial[i] = sequence[i];
  21.             }
  22.             while (true)
  23.             {
  24.                 for (int i = 0; i < field.Length; i++)
  25.                 {
  26.                     field[i]--;
  27.                 }
  28.                 if (field[index] == 0)
  29.                 {
  30.                     break;
  31.                 }
  32.                 for (int i = 0; i < field.Length; i++)
  33.                 {
  34.                     if (field[i] == 0)
  35.                     {
  36.                         field[i] = initial[i];
  37.                     }
  38.                 }
  39.                 steps++;
  40.                 index = int.Parse(Console.ReadLine());
  41.             }
  42.             Console.WriteLine(string.Join(" ", field));
  43.             Console.WriteLine(steps);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement