svetlozar_kirkov

PaintBall

May 3rd, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PaintBall
  4. {
  5.     class PaintBall
  6.     {
  7.         static void Main()
  8.         {
  9.             int[,] field = new int[10,10];
  10.             for (int i = 0; i < 10; i++)
  11.             {
  12.                 for (int j = 0; j < 10; j++)
  13.                 {
  14.                     field[i, j] = 1;
  15.                 }
  16.             }
  17.             int currentPaint = 0;
  18.             string inputLine = Console.ReadLine();
  19.             while (inputLine != "End")
  20.             {
  21.                 string[] inputSplit = inputLine.Split(' ');
  22.                 int row = Convert.ToInt32(inputSplit[0]);
  23.                 int col = Convert.ToInt32(inputSplit[1]);
  24.                 int radius = Convert.ToInt32(inputSplit[2]);
  25.                 for (int i = 0; i < 10; i++)
  26.                 {
  27.                     for (int j = 0; j < 10; j++)
  28.                     {
  29.                         if (i >= row - radius && j >= col - radius && i <= row + radius && j <= col + radius)
  30.                         {
  31.                             field[i, j] = currentPaint;
  32.                         }
  33.                     }
  34.                 }
  35.                 if (currentPaint == 0)
  36.                 {
  37.                     currentPaint = 1;
  38.                 }
  39.                 else
  40.                 {
  41.                     currentPaint = 0;
  42.                 }
  43.                 inputLine = Console.ReadLine();
  44.             }
  45.             int sum = 0;
  46.             for (int i = 0; i < 10; i++)
  47.             {
  48.                 string current = "";
  49.                 for (int j = 0; j < 10; j++)
  50.                 {
  51.                     current += field[i, j];
  52.                 }
  53.                 current = ReverseString(current);
  54.                 sum += Convert.ToInt32(current, 2);
  55.             }
  56.             Console.WriteLine(sum);
  57.         }
  58.         public static string ReverseString(string s)
  59.         {
  60.             char[] arr = s.ToCharArray();
  61.             Array.Reverse(arr);
  62.             return new string(arr);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment