Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. string[] r = Console.ReadLine().Split(' ');
  10. int n = int.Parse(r[0]), m = int.Parse(r[1]);
  11. int[,] a = new int[n, m];
  12. for (int i = 0; i < n; i++)
  13. {
  14. int[] b = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15. for (int j = 0; j < m; j++)
  16. a[i, j] = b[j];
  17. }
  18. int s1, s2, s3, s4;
  19. s1 = s2 = s3 = s4 = 0;
  20. for (int i = 0; i < n; i++)
  21. for (int j = 0; j < m; j++)
  22. {
  23. if (i == j)
  24. s1 += a[i, j];
  25. if (i + j == n - 1)
  26. s2 += a[i, j];
  27. if (i < j)
  28. s3 += a[i, j];
  29. if (i > j)
  30. s4 += a[i, j];
  31. }
  32. if (s1 == s2 && s3 % 2 == 0 && s4 % 2 != 0)
  33. {
  34. s1 = s2 = s3 = s4 = 0;
  35. for (int i = 0; i < n; i++)
  36. for (int j = 0; j < m; j++)
  37. {
  38. if (i > j)
  39. s1 += a[i, j];
  40. if (i == j && a[i, j] % 2 == 0)
  41. s2 += a[i, j];
  42. if (((i == 0) || (i == n - 1)) && (a[i, j] % 2 == 0))
  43. s3 += a[i, j];
  44. if (((j == 0) || (j == m - 1)) && (a[i, j] % 2 != 0))
  45. s4 += a[i, j];
  46. }
  47.  
  48. Console.WriteLine("YES\nThe amount of money won is: {0:0.00}", Math.Round((s1+s2+s3+s4)/4.0,2));
  49. }
  50. else
  51. Console.WriteLine("NO");
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement