Created
March 29, 2015 13:09
-
-
Save alagalia/6b564158df83c5bf648a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class FunwithMatrices | |
{ | |
static void Main() | |
{ | |
double startNumber = double.Parse(Console.ReadLine()); | |
double step = double.Parse(Console.ReadLine()); | |
double[,] matrix = new double[4, 4]; | |
for (int r = 0; r< 4; r++) | |
{ | |
for (int c = 0; c < 4; c++) | |
{ | |
matrix[r, c] = startNumber; | |
startNumber = startNumber + step; | |
} | |
} | |
bool gameOver = true; | |
while (gameOver) | |
{ | |
string[] commandAsString = Console.ReadLine().Split(' '); | |
if (commandAsString[0] != "Game") | |
{ | |
int row = int.Parse(commandAsString[0]); | |
int col = int.Parse(commandAsString[1]); | |
double num = double.Parse(commandAsString[3]); | |
switch (commandAsString[2]) | |
{ | |
case "multiply": matrix[row, col] *= num; break; | |
case "sum": matrix[row, col] += num; break; | |
case "power": matrix[row, col] = Math.Pow(matrix[row, col], num); ; break; | |
} | |
} | |
else | |
{ | |
gameOver = false; | |
} | |
} | |
//check the bigest sum | |
double sumZeroRow = matrix[0, 0] + matrix[0, 1] + matrix[0, 2] + matrix[0, 3]; | |
double sumFirstRow= matrix[1, 0] + matrix[1, 1] + matrix[1, 2] + matrix[1, 3]; | |
double sumSeconddRow = matrix[2, 0] + matrix[2, 1] + matrix[2, 2] + matrix[2, 3]; | |
double sumThirdRow = matrix[3, 0] + matrix[3, 1] + matrix[3, 2] + matrix[3, 3]; | |
double sumZeroCol = matrix[0, 0] + matrix[1, 0] + matrix[2, 0] + matrix[3, 0]; | |
double sumFirstCol = matrix[0, 1] + matrix[1, 1] + matrix[2, 1] + matrix[3, 1]; | |
double sumSeconddCol = matrix[0, 2] + matrix[1, 2] + matrix[2, 2] + matrix[3, 2]; | |
double sumThirdCol = matrix[0, 3] + matrix[1, 3] + matrix[2, 3] + matrix[3, 3]; | |
double leftDiagonal = matrix[0, 0] + matrix[1, 1] + matrix[2, 2] + matrix[3, 3]; | |
double rightDiagonal = matrix[0, 3] + matrix[1, 2] + matrix[2, 1] + matrix[3, 0]; | |
double[] matrixSum = { sumZeroRow, sumFirstRow, sumSeconddRow, sumThirdRow, sumZeroCol, sumFirstCol, sumSeconddCol, sumThirdCol, leftDiagonal, rightDiagonal }; | |
double largestSum = 0; | |
string element=""; | |
int index=0; | |
for (int i = 0; i < 4; i++) | |
{ | |
if (matrixSum[i]>largestSum) | |
{ | |
largestSum = matrixSum[i]; | |
element = "ROW"; | |
index = i; | |
} | |
} | |
for (int i = 4; i < 8; i++) | |
{ | |
if (matrixSum[i] > largestSum) | |
{ | |
largestSum = matrixSum[i]; | |
element = "COLUMN"; | |
index = i-4; | |
} | |
} | |
if (matrixSum[8] > largestSum) | |
{ | |
largestSum = matrixSum[8]; | |
element = "LEFT-DIAGONAL"; | |
} | |
if (matrixSum[9] > largestSum) | |
{ | |
largestSum = matrixSum[9]; | |
element = "RIGHT-DIAGONAL"; | |
} | |
if (element == "RIGHT-DIAGONAL" || element == "LEFT-DIAGONAL") | |
{ | |
Console.WriteLine(element+" = " +"{0:0.00}", largestSum); | |
} | |
else | |
{ | |
Console.WriteLine(element + "["+index+ "] = "+ "{0:0.00}", largestSum); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment