Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SumMatrixElements
- {
- using System;
- using System.Linq;
- using System.Text;
- public class Startup
- {
- private static int totalSum;
- public static void Main()
- {
- int[] dimensions = SplitStringToArray();
- int rowsOfMatrix = dimensions[0];
- int colsOfMatrix = dimensions[1];
- int[][] matrix = new int[rowsOfMatrix][];
- totalSum = 0;
- for (int row = 0; row < rowsOfMatrix; row++)
- {
- SplitStringToArray();
- }
- StringBuilder result = new StringBuilder();
- result.AppendLine(rowsOfMatrix.ToString());
- result.AppendLine(colsOfMatrix.ToString());
- result.AppendLine(totalSum.ToString());
- Console.Write(result);
- }
- private static int[] SplitStringToArray()
- {
- return Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(ParseAndAddNumberToSum).ToArray();
- }
- private static int ParseAndAddNumberToSum(string numberToParse)
- {
- int numberToReturn = int.Parse(numberToParse);
- totalSum += numberToReturn;
- return numberToReturn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement