Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 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. class Program
  8. {
  9.     public static string GetBikeChipPosition(int[][] chips, int x)
  10.     {
  11.         int z = 0;
  12.  
  13.         Console.WriteLine(string.Format("Input: {0}", x));
  14.  
  15.         for(int i=0; i <= chips.Length; i++)
  16.         {
  17.             if (x <= chips[i].Length + z - 2 + i)
  18.             {
  19.                 return string.Format("Chip: {0} // Bike: {1}", i, x - z - Convert.ToInt32(i>1));
  20.             } else
  21.             {
  22.                 z += chips[i].Length;
  23.             }
  24.         }
  25.  
  26.         return "OUT OF RANGE";
  27.     }
  28.  
  29.     static void Main(string[] args)
  30.     {
  31.         int[][] chips = new int[4][];
  32.         chips[0] = new int[7];
  33.         chips[1] = new int[4];
  34.         chips[2] = new int[2];
  35.         chips[3] = new int[6];
  36.  
  37.         Console.WriteLine( GetBikeChipPosition(chips, 0) );
  38.  
  39.         Console.ReadLine();
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement