svetlozar_kirkov

Bit Shooter

Sep 15th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace BitShooter
  6. {
  7.     class BitShooter
  8.     {
  9.         static void Main()
  10.         {
  11.             UInt64 input = UInt64.Parse(Console.ReadLine());
  12.             string[] shot1 = Console.ReadLine().Split(' ');
  13.             string[] shot2 = Console.ReadLine().Split(' ');
  14.             string[] shot3 = Console.ReadLine().Split(' ');
  15.            
  16.             string initial = Convert.ToString((long)input, 2).PadLeft(64, '0');
  17.             string[] initialArray = initial.Select(c => c.ToString()).ToArray();
  18.  
  19.             int[] shots = new int[3] { Convert.ToInt32(shot1[0]), Convert.ToInt32(shot2[0]),
  20.                 Convert.ToInt32(shot3[0]) };
  21.             int[] ranges = new int[3] { Convert.ToInt32(shot1[1]), Convert.ToInt32(shot2[1]),
  22.                 Convert.ToInt32(shot3[1]) };
  23.            
  24.  
  25.             //foreach (var item in initialArray)
  26.             //{
  27.             //    Console.Write(item);
  28.             //}
  29.  
  30.             //Console.WriteLine();
  31.  
  32.             Array.Reverse(initialArray);
  33.  
  34.             for (int x = 0; x < 3; x++)
  35.             {
  36.                 for (int i = 0; i < initialArray.Length; i++)
  37.                 {
  38.                     if (i == shots[x])
  39.                     {
  40.                         if (i - (ranges[x] / 2) < 0)
  41.                         {
  42.                             //int temp = i - Convert.ToInt32(shot1[1]) / 2;
  43.                             for (int j = 0; j <= shots[x]+ranges[x]/2; j++)
  44.                             {
  45.                                 initialArray[j] = "0";
  46.                             }
  47.                         }
  48.                         else if (i + ranges[x] / 2 > 64)
  49.                         {
  50.                             //int temp = i - Convert.ToInt32(shot1[1]) / 2;
  51.                             for (int j = shots[x] - ranges[x] / 2; j < 64; j++)
  52.                             {
  53.                                 initialArray[j] = "0";
  54.                             }
  55.                         }
  56.                         else
  57.                         {
  58.                             for (int j = i - (ranges[x] / 2); j < i - (ranges[x] / 2) + ranges[x]; j++)
  59.                             {
  60.                                 initialArray[j] = "0";
  61.                             }
  62.                         }
  63.  
  64.  
  65.  
  66.                     }
  67.                 }
  68.             }
  69.            
  70.  
  71.             Array.Reverse(initialArray);
  72.  
  73.             int leftcount = 0;
  74.             int rightcount = 0;
  75.  
  76.             for (int i = 0; i < initialArray.Length; i++)
  77.             {
  78.                 if (i < 32)
  79.                 {
  80.                     if (initialArray[i] == "1")
  81.                     {
  82.                         leftcount++;
  83.                     }
  84.                 }
  85.                 else if(i >=32 && i < initialArray.Length)
  86.                 {
  87.                     if (initialArray[i] == "1")
  88.                     {
  89.                         rightcount++;
  90.                     }
  91.                 }
  92.             }
  93.  
  94.             //foreach (var item in initialArray)
  95.             //{
  96.             //    Console.Write(item);
  97.             //}
  98.  
  99.             Console.WriteLine("left: " + leftcount);
  100.             Console.WriteLine("right: " + rightcount);
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment