Advertisement
Prohause

Cubic's Ruse

Jun 21st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace CubicsRube
  9. {
  10. public class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. var dimension = int.Parse(Console.ReadLine());
  15. var cube = CreateAnFill(dimension);
  16.  
  17. var input = Console.ReadLine();
  18.  
  19. while (input!=null&&!input.Equals("Analyze"))
  20. {
  21. var coordinates = input.Split(new[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries)
  22. .Select(int.Parse).ToArray();
  23. var xPos = coordinates[0];
  24. var yPos = coordinates[1];
  25. var zPos = coordinates[2];
  26. var partSize = coordinates[3];
  27. try
  28. {
  29. if (cube[xPos][yPos][zPos]==0)
  30. {
  31. cube[xPos][yPos][zPos] = partSize;
  32. }
  33. }
  34. catch (Exception)
  35. {
  36. //ignored
  37. }
  38. input = Console.ReadLine();
  39. }
  40.  
  41. var count = 0;
  42. var sum = BigInteger.Zero;
  43.  
  44. for (var i = 0; i < dimension; i++)
  45. {
  46. for (var j = 0; j < dimension; j++)
  47. {
  48. for (var k = 0; k < dimension; k++)
  49. {
  50. if (cube[i][j][k]==0)
  51. {
  52. count++;
  53. }
  54. else
  55. {
  56. sum += cube[i][j][k];
  57. }
  58. }
  59. }
  60. }
  61.  
  62. Console.WriteLine(sum);
  63. Console.WriteLine(count);
  64.  
  65. }
  66.  
  67. private static int[][][] CreateAnFill(int dimension)
  68. {
  69. var matrix = new int[dimension][][];
  70. for (var i = 0; i < dimension; i++)
  71. {
  72. matrix[i]= new int[dimension][];
  73. for (var j = 0; j < dimension; j++)
  74. {
  75. matrix[i][j] = new int[dimension];
  76. for (var k = 0; k < dimension; k++)
  77. {
  78. matrix[i][j][k] = 0;
  79. }
  80. }
  81.  
  82. }
  83. return matrix;
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement