Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static int CountTotalMoney(char[,] userInput)
- {
- int numDollars = 0;
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- if (userInput[j, i] == '$')
- {
- numDollars++;
- }
- }
- }
- return numDollars;
- }
- static bool CheckValid (ref char[,] userInputs, int row, int column)
- {
- bool validPoint = false;
- if (row < 0 || row >= userInputs.GetLength(0) || column < 0 || column >= userInputs.GetLength(1))
- {
- validPoint = false;
- }
- if (userInputs[column, row] == '$')
- {
- validPoint = true;
- userInputs[column, row] = '!';
- }
- else
- {
- validPoint= false;
- }
- return validPoint;
- }
- static int CountMoneyPotSize (char[,] userInputs, int row, int column)
- {
- if(CheckValid(ref userInputs, row, column))
- {
- CountMoneyPotSize(userInputs, row, column);
- }
- else if (CheckValid(ref userInputs, row + 1, column))
- {
- CountMoneyPotSize(userInputs, row + 1, column);
- }
- else if (CheckValid(ref userInputs, row - 1, column))
- {
- CountMoneyPotSize(userInputs, row - 1, column);
- }
- else if (CheckValid(ref userInputs, row, column + 1))
- {
- CountMoneyPotSize(userInputs, row, column + 1);
- }
- else if (CheckValid(ref userInputs, row, column - 1))
- {
- CountMoneyPotSize(userInputs, row, column - 1);
- }
- return (CountValidPoints(userInputs));
- }
- static int CountValidPoints(char[,] userInput)
- {
- int numCells = 0;
- for(int i = 0; i < 5; i++)
- {
- for(int j = 0; j < 8; j++)
- {
- if (userInput[j,i] == '!')
- {
- numCells++;
- }
- }
- }
- return numCells;
- }
- static void Main(string[] args)
- {
- char[,] userMatrix = new char[8,5];
- StreamReader sr = new StreamReader("payday.txt");
- for (int i = 0; i < 5; i++)
- {
- string matrixRow = sr.ReadLine();
- for (int j = 0; j < 8; j++)
- {
- userMatrix[j,i] = matrixRow[j];
- }
- }
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- Console.Write(userMatrix[j,i]);
- }
- Console.Write("\n");
- }
- int numDollars = CountTotalMoney(userMatrix);
- int numObjects = CountMoneyPotSize(userMatrix, 0, 4);
- Console.WriteLine(numObjects);
- Console.WriteLine(numDollars);
- Console.ReadKey(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement