Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Opdracht_1
  4. {
  5.     class Program
  6.     {
  7.         public static UInt64 a;
  8.         public static UInt64 b;
  9.         public static UInt64 c;
  10.  
  11.         public static UInt64 Zoeklevel(UInt64 input, UInt64[] levelpoints)
  12.         {
  13.             UInt64 low = 0;
  14.             UInt64 high = (UInt64) levelpoints.Length - 1;
  15.             UInt64 mid = 0;
  16.  
  17.             while (low < high)
  18.             {
  19.                 mid = (low + high) / 2;
  20.                 if (input < levelpoints[mid])
  21.                 {
  22.                     high = mid;
  23.                 }
  24.                 else
  25.                 {
  26.                     low = mid + 1;
  27.                 }
  28.             }
  29.             return low;
  30.         }
  31.  
  32.         public static UInt64[] Setup()
  33.         {
  34.             UInt64[] levelspunten = new UInt64[c];
  35.             levelspunten[0] = 0;
  36.             levelspunten[1] = a;
  37.             for (UInt32 i = 2; i < c; i++)
  38.             {
  39.                 levelspunten[i] = a + ((a + (b / 2)) / b);
  40.                 a = levelspunten[i];
  41.             }
  42.             return levelspunten;
  43.         }
  44.  
  45.         public static void Run()
  46.         {
  47.             try
  48.             {
  49.                 Console.WriteLine("Voer Alfa, Beta en Gamma in. Scheid uw invoer met spaties.");
  50.                 string[] invoer1 = Console.ReadLine().Split(' ');
  51.                 a = UInt64.Parse(invoer1[0]);
  52.                 b = UInt64.Parse(invoer1[1]);
  53.                 c = UInt64.Parse(invoer1[2]);
  54.                 UInt64[] levels = Program.Setup();
  55.                 Console.WriteLine("Correcte invoer. Voer nu het aantal punten in om het bijbehorende level uit te rekenen.");
  56.                 foreach (UInt64 k in levels)
  57.                 {
  58.                     Console.WriteLine(k);
  59.                 }
  60.                 while (true)
  61.                     Console.WriteLine(Zoeklevel(UInt64.Parse(Console.ReadLine()), levels).ToString());
  62.  
  63.             }
  64.             catch
  65.             {
  66.                 Console.WriteLine("Incorrecte invoer. Probeer het opnieuw!");
  67.                 Program.Run();
  68.             }
  69.         }
  70.         static void Main()
  71.         {
  72.             Program.Run();
  73.             Console.ReadKey(true);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement