Advertisement
bullit3189

Cubic's Rube

Jun 11th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. namespace P02_CubicsRube
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public class CubicsRube
  7. {
  8. public static void Main()
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. long sum = 0;
  12. int changedCells = 0;
  13.  
  14. while (true)
  15. {
  16. var input = Console.ReadLine();
  17.  
  18. if (input == "Analyze")
  19. {
  20. Console.WriteLine(sum);
  21. Console.WriteLine(Math.Pow(n, 3) - changedCells);
  22. break;
  23. }
  24.  
  25. var coordinates = input.Split().Select(int.Parse).ToArray();
  26. int table = coordinates[0];
  27. int row = coordinates[1];
  28. int col = coordinates[2];
  29. int value = coordinates[3];
  30.  
  31. if (HasValidCoordinates(table, row, col, n) && value != 0)
  32. {
  33. sum += value;
  34. changedCells++;
  35. }
  36. }
  37. }
  38.  
  39. public static bool HasValidCoordinates(int table, int row, int col, int n)
  40. {
  41. if (table >= 0 && table < n
  42. && row >= 0 && row < n
  43. && col >= 0 && col < n)
  44. {
  45. return true;
  46. }
  47.  
  48. return false;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement