Advertisement
GPipkov

FunWithMatrices

Aug 21st, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FunWithMatrix
  8. {
  9.     class FunWithMatrix
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double start = double.Parse(Console.ReadLine());
  14.             double steps = double.Parse(Console.ReadLine());
  15.  
  16.             double[,] matrix = new double[4, 4];
  17.  
  18.             for (int row = 0; row < 4; row++)
  19.             {
  20.                 for (int col = 0; col < 4; col++)
  21.                 {
  22.                     matrix[row, col] = start;
  23.                     start += steps;
  24.  
  25.                 }
  26.             }
  27.             string operations = Console.ReadLine();
  28.  
  29.             while (operations != "Game Over!")
  30.             {
  31.                 string[] data = operations.Split(' ');
  32.                 int row = int.Parse(data[0]);
  33.                 int col = int.Parse(data[1]);
  34.                 string orders = data[2];
  35.                 double num = double.Parse(data[3]);
  36.                 switch (orders)
  37.                 {
  38.                     case "multiply": matrix[row, col] *= num; break;
  39.                     case "sum": matrix[row, col] += num; break;
  40.                     case "power": matrix[row, col] = Math.Pow(matrix[row, col], num); break;
  41.                     default:
  42.                         break;
  43.                
  44.                 }
  45.                 operations = Console.ReadLine();      
  46.             }
  47.             double maxSum = double.MinValue;
  48.             int index = 0;
  49.             string maxType = "ROW";
  50.             for (int row = 0; row < 4; row++)
  51.             {
  52.                 double sum = matrix[row, 0] + matrix[row, 1] + matrix[row, 2] + matrix[row, 3];
  53.  
  54.                 if (sum > maxSum)
  55.                 {
  56.                     maxSum = sum;
  57.                     index = row;
  58.                 }
  59.             }
  60.             for (int col = 0; col < 4; col++)
  61.             {
  62.                 double sum = matrix[0, col] + matrix[1, col] + matrix[2, col] + matrix[3, col];
  63.                 if (sum > maxSum)
  64.                 {
  65.                     maxSum = sum;
  66.                     index = col;
  67.                     maxType = "COLUMN";
  68.                 }
  69.             }
  70.  
  71.             double leftDiagonal = matrix[0, 0] + matrix[1, 1] + matrix[2, 2] + matrix[3, 3];
  72.             if (leftDiagonal > maxSum)
  73.             {
  74.                 leftDiagonal = maxSum;
  75.                 maxType = "LEFT-DIAGONAL";
  76.             }
  77.             double rightDiagonal = matrix[3, 0] + matrix[2, 1] + matrix[1, 2] + matrix[0, 3];
  78.             if (rightDiagonal > maxSum)
  79.             {
  80.                 rightDiagonal = maxSum;
  81.                 maxType = "RIGHT-DIAGONAL";
  82.             }
  83.             if (maxType == "ROW" || maxType == "COLUMN")
  84.             {
  85.                 Console.WriteLine("{0}[{1}] = {2:F2}", maxType, index, maxSum);
  86.             }
  87.             else
  88.             {
  89.                 Console.WriteLine("{0} = {1:F2}", maxType, maxSum);
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement