Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. class Program
  2. {
  3.  
  4. static int CountTotalMoney(char[,] userInput)
  5. {
  6.  
  7. int numDollars = 0;
  8.  
  9. for (int i = 0; i < 5; i++)
  10. {
  11. for (int j = 0; j < 8; j++)
  12. {
  13. if (userInput[j, i] == '$')
  14. {
  15. numDollars++;
  16. }
  17. }
  18. }
  19.  
  20. return numDollars;
  21.  
  22. }
  23.  
  24. static bool CheckValid (ref char[,] userInputs, int row, int column)
  25. {
  26. bool validPoint = false;
  27.  
  28. if (row < 0 || row >= userInputs.GetLength(0) || column < 0 || column >= userInputs.GetLength(1))
  29. {
  30.  
  31. validPoint = false;
  32.  
  33. }
  34.  
  35. if (userInputs[column, row] == '$')
  36. {
  37.  
  38. validPoint = true;
  39. userInputs[column, row] = '!';
  40.  
  41. }
  42. else
  43. {
  44.  
  45. validPoint= false;
  46.  
  47. }
  48.  
  49. return validPoint;
  50. }
  51.  
  52. static int CountMoneyPotSize (char[,] userInputs, int row, int column)
  53. {
  54.  
  55. if(CheckValid(ref userInputs, row, column))
  56. {
  57.  
  58. CountMoneyPotSize(userInputs, row, column);
  59.  
  60. }
  61.  
  62. else if (CheckValid(ref userInputs, row + 1, column))
  63. {
  64.  
  65. CountMoneyPotSize(userInputs, row + 1, column);
  66.  
  67.  
  68. }
  69. else if (CheckValid(ref userInputs, row - 1, column))
  70. {
  71.  
  72. CountMoneyPotSize(userInputs, row - 1, column);
  73.  
  74. }
  75. else if (CheckValid(ref userInputs, row, column + 1))
  76. {
  77.  
  78. CountMoneyPotSize(userInputs, row, column + 1);
  79.  
  80. }
  81. else if (CheckValid(ref userInputs, row, column - 1))
  82. {
  83.  
  84. CountMoneyPotSize(userInputs, row, column - 1);
  85.  
  86. }
  87.  
  88. return (CountValidPoints(userInputs));
  89.  
  90. }
  91.  
  92. static int CountValidPoints(char[,] userInput)
  93. {
  94.  
  95. int numCells = 0;
  96. for(int i = 0; i < 5; i++)
  97. {
  98. for(int j = 0; j < 8; j++)
  99. {
  100. if (userInput[j,i] == '!')
  101. {
  102. numCells++;
  103. }
  104. }
  105. }
  106.  
  107. return numCells;
  108. }
  109.  
  110.  
  111.  
  112. static void Main(string[] args)
  113. {
  114. char[,] userMatrix = new char[8,5];
  115. StreamReader sr = new StreamReader("payday.txt");
  116.  
  117. for (int i = 0; i < 5; i++)
  118. {
  119. string matrixRow = sr.ReadLine();
  120.  
  121. for (int j = 0; j < 8; j++)
  122. {
  123. userMatrix[j,i] = matrixRow[j];
  124. }
  125.  
  126. }
  127.  
  128. for (int i = 0; i < 5; i++)
  129. {
  130. for (int j = 0; j < 8; j++)
  131. {
  132. Console.Write(userMatrix[j,i]);
  133. }
  134. Console.Write("\n");
  135. }
  136. int numDollars = CountTotalMoney(userMatrix);
  137. int numObjects = CountMoneyPotSize(userMatrix, 0, 4);
  138. Console.WriteLine(numObjects);
  139. Console.WriteLine(numDollars);
  140.  
  141. Console.ReadKey(true);
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement