Advertisement
fbinnzhivko

Chessboard Game

Mar 19th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         var boardSize = int.Parse(Console.ReadLine());
  7.         string inputstrings = Console.ReadLine();
  8.  
  9.         var whiteTeamScore = 0;
  10.         var blackTeamScore = 0;
  11.  
  12.         int cellsCount = boardSize * boardSize;
  13.  
  14.         if (cellsCount > inputstrings.Length)
  15.         {
  16.             string additionalCharacters = new string(' ', cellsCount - inputstrings.Length);
  17.             inputstrings = inputstrings + additionalCharacters;
  18.         }
  19.  
  20.  
  21.         for (int letter = 0; letter < cellsCount; letter++)
  22.         {
  23.             char currentChar = inputstrings[letter];
  24.  
  25.             if ((currentChar >= 'a' && currentChar <= 'z') || (currentChar >= 'A' && currentChar <= 'Z') || (currentChar >= '0' && currentChar <= '9'))
  26.             {
  27.                 if (letter % 2 == 0)
  28.                 {
  29.                     if (currentChar >= 'A' && currentChar <= 'Z')
  30.                     {
  31.                         whiteTeamScore = whiteTeamScore + currentChar;
  32.                     }
  33.                     else
  34.                     {
  35.                         blackTeamScore = blackTeamScore + currentChar;
  36.                     }
  37.  
  38.                 }
  39.                 else
  40.                 {
  41.                     if (currentChar >= 'A' && currentChar <= 'Z')
  42.                     {
  43.  
  44.                         blackTeamScore = blackTeamScore + currentChar;
  45.                     }
  46.                     else
  47.                     {
  48.                         whiteTeamScore = whiteTeamScore + currentChar;
  49.                     }
  50.  
  51.                 }
  52.             }
  53.  
  54.         }
  55.         if (blackTeamScore < whiteTeamScore)
  56.         {
  57.             Console.WriteLine("The winner is: white team");
  58.             Console.WriteLine(whiteTeamScore - blackTeamScore);
  59.         }
  60.         else if (blackTeamScore > whiteTeamScore)
  61.         {
  62.             Console.WriteLine("The winner is: black team");
  63.             Console.WriteLine(blackTeamScore - whiteTeamScore);
  64.         }
  65.  
  66.  
  67.         else if (whiteTeamScore == blackTeamScore)
  68.         {
  69.             Console.WriteLine("Equal result: {0}", blackTeamScore);
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement