Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Linq;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- var matrixTxT = File.ReadAllText(@"E:\Downloads\ChromeDownloads\matrix.txt");
- // var str = matrixTxT.Split(new char[] { '\t', '\n'}, StringSplitOptions.RemoveEmptyEntries);
- /* string[] wordsArray = matrixTxT.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
- foreach(string word in wordsArray)
- {
- Console.Write(word+" ");
- }
- */
- // var rows= File.ReadAllLines(@"E:\Downloads\ChromeDownloads\matrix.txt").Length;
- // var cols =(str.Length/rows);
- int rows = int.Parse(Console.ReadLine());
- int cols = int.Parse(Console.ReadLine());
- int i = 0 , k = 0;
- int[,] matrix = new int[rows, cols];
- // Console.WriteLine($"\nRows:{rows} Cols:{cols} Items:{str.Length}");
- foreach (var row in matrixTxT.Split('\n'))
- {
- string[] input = row.Split("\t");
- int r = int.Parse(input[0])-1;
- int c = int.Parse(input[1])-1;
- if (input[2].Equals(" ") || input[2].Equals(" \r"))
- {
- matrix[r, c] = -1;
- }
- else
- {
- matrix[r, c] = int.Parse(input[2]);
- }
- }
- int evenSum = 0;
- int oddSum = 0;
- int oddColSum = 0;
- int evenRowSum = 0;
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- int num = matrix[row, col];
- if (num % 2 == 0)
- {
- evenSum += num;
- }
- else if(num % 2 != 0)
- {
- oddSum += num;
- }
- if (col % 2==0 )
- {
- oddColSum += num;
- }
- if(row % 2 != 0)
- {
- evenRowSum += num;
- }
- Console.Write(matrix[row,col]+" ");
- }
- Console.WriteLine();
- }
- Console.WriteLine($"Even numbers sum: {evenSum}\nOdd numbers sum: {oddSum}");
- Console.WriteLine($"Odd column sum: {oddColSum}\nEven row sum: {evenRowSum}");
- }
- }
- }
- /* test input
- 1 1 2
- 1 2 1
- 1 3
- 1 4 5
- 2 1 2
- 2 2 1
- 2 3 7
- 2 4 3
- 3 1 2
- 3 2 1
- 3 3 4
- 3 4 5
- 4 1 3
- 4 2 5
- 4 3 6
- 4 4
- */
Add Comment
Please, Sign In to add comment