Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. namespace CsvMatrix
  2. {
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. var matrix1 = ReadMatrix(File.ReadAllLines("matrix1.csv"));
  12. var matrix2 = ReadMatrix(File.ReadAllLines("matrix2.csv"));
  13.  
  14. if (matrix1.GetLength(0) != matrix2.GetLength(0) ||
  15. matrix1.GetLength(1) != matrix2.GetLength(1))
  16. {
  17. Console.WriteLine("undefined");
  18. return;
  19. }
  20.  
  21. Console.WriteLine(CheckForSymmetry(matrix1, matrix2));
  22. }
  23.  
  24. private static int[,] ReadMatrix(string[] rows)
  25. {
  26. var cols = rows[0].Split(',');
  27. var matrix = new int[rows.Length, cols.Length];
  28.  
  29. for (int i = 0; i < rows.Length; i++)
  30. {
  31. var numbers = rows[i].Split(',').Select(int.Parse).ToArray();
  32.  
  33. for (int j = 0; j < cols.Length; j++)
  34. {
  35. matrix[i, j] = numbers[j];
  36. }
  37. }
  38.  
  39. return matrix;
  40. }
  41.  
  42. private static bool CheckForAntisymmetry(int[,] matrix1, int[,] matrix2)
  43. {
  44. for (int i = 0; i < matrix1.GetLength(0); i++)
  45. {
  46. for (int j = 0; j < matrix1.GetLength(1); j++)
  47. {
  48. if (matrix1[i, j] != -matrix2[i, j])
  49. {
  50. return false;
  51. }
  52. }
  53. }
  54.  
  55. return true;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement