Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FunWithMatrix
- {
- class FunWithMatrix
- {
- static void Main(string[] args)
- {
- double start = double.Parse(Console.ReadLine());
- double steps = double.Parse(Console.ReadLine());
- double[,] matrix = new double[4, 4];
- for (int row = 0; row < 4; row++)
- {
- for (int col = 0; col < 4; col++)
- {
- matrix[row, col] = start;
- start += steps;
- }
- }
- string operations = Console.ReadLine();
- while (operations != "Game Over!")
- {
- string[] data = operations.Split(' ');
- int row = int.Parse(data[0]);
- int col = int.Parse(data[1]);
- string orders = data[2];
- double num = double.Parse(data[3]);
- switch (orders)
- {
- 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;
- default:
- break;
- }
- operations = Console.ReadLine();
- }
- double maxSum = double.MinValue;
- int index = 0;
- string maxType = "ROW";
- for (int row = 0; row < 4; row++)
- {
- double sum = matrix[row, 0] + matrix[row, 1] + matrix[row, 2] + matrix[row, 3];
- if (sum > maxSum)
- {
- maxSum = sum;
- index = row;
- }
- }
- for (int col = 0; col < 4; col++)
- {
- double sum = matrix[0, col] + matrix[1, col] + matrix[2, col] + matrix[3, col];
- if (sum > maxSum)
- {
- maxSum = sum;
- index = col;
- maxType = "COLUMN";
- }
- }
- double leftDiagonal = matrix[0, 0] + matrix[1, 1] + matrix[2, 2] + matrix[3, 3];
- if (leftDiagonal > maxSum)
- {
- leftDiagonal = maxSum;
- maxType = "LEFT-DIAGONAL";
- }
- double rightDiagonal = matrix[3, 0] + matrix[2, 1] + matrix[1, 2] + matrix[0, 3];
- if (rightDiagonal > maxSum)
- {
- rightDiagonal = maxSum;
- maxType = "RIGHT-DIAGONAL";
- }
- if (maxType == "ROW" || maxType == "COLUMN")
- {
- Console.WriteLine("{0}[{1}] = {2:F2}", maxType, index, maxSum);
- }
- else
- {
- Console.WriteLine("{0} = {1:F2}", maxType, maxSum);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement