Advertisement
VyaraG

TicTacToe

Dec 11th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. //You are given tic-tac-toe board (3 columns and 3 rows) like the one the right. As inputs you will be given the X and Y coordinates of one of the cells. Each of the cells in the field has an index and a value (look at the examples on the right). You will be given the value of the first cell V (index1). Each of the next cells will have value greater by 1 than the previous. Example: if value=80, then index1=80, index2=81, index3=82, ..., index9=89. Your task is to print on the console the value of the cell C raised to the power of its index: C index. Look at comments in the examples below to understand your task better.
  2. //Input
  3. //The input data should be read from the console.
  4. //•   At the first line you will be given the X coordinate.
  5. //•   At the second line you will be given the Y coordinate.
  6. //•   At the third line an integer number V will be given, specifying the value of the first cell.
  7. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  8. //Output
  9. //The output should be printed on the console. It should consist of 1 line:
  10. //•   Print the value C of the cell at position {X, Y} raised to the power of its index.
  11. //Constraints
  12. //•   The X and Y inputs will be integers in the range [0…2].
  13. //•   The V input will be an integer in the range [0…100].
  14. //•   Allowed working time: 0.2 seconds. Allowed memory: 16 MB.
  15.  
  16.  
  17.  
  18. using System;
  19.  
  20. class TicTacToe
  21. {
  22.     static void Main()
  23.     {
  24.         int x = int.Parse(Console.ReadLine());
  25.         int y = int.Parse(Console.ReadLine());
  26.         int firstValue = int.Parse(Console.ReadLine());
  27.  
  28.         long result = 0;
  29.         int position = x + 1;  // 1, 2, 3
  30.         if (y == 1)
  31.         {
  32.             position = x + 4;  // 4, 5, 6
  33.         }
  34.         else if (y == 2)
  35.         {
  36.             position = x + 7;  // 7, 8, 9
  37.         }
  38.         firstValue += position - 1;
  39.         result = (long)Math.Pow(firstValue, position);
  40.         Console.WriteLine(result);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement