fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. class Vestigium {
  7. public static int countFreq(int[] arr, int n) {
  8. for (int i = 0; i < n; i++) {
  9. for (int j = i + 1; j < n; j++) {
  10. if (arr[i] == arr[j]) {
  11. return 1;
  12. }
  13. }
  14. }
  15. return 0;
  16. }
  17. public static int getoutPut(int[, ] arr1, int n) {
  18. int k = 0;
  19. for (int i = 0; i < n; i++) {
  20. k += arr1[i, i];
  21. }
  22. return k;
  23. }
  24. }
  25.  
  26. class Solution {
  27. public static void Main() {
  28. try {
  29. int t = Convert.ToInt32(Console.ReadLine());
  30. for (int tc = 0; tc < t; tc++) {
  31. int n = Convert.ToInt32(Console.ReadLine());
  32. int[, ] arr1 = new int[n, n];
  33. for (int index = 0; index < n; index++) {
  34. string str = Console.ReadLine();
  35. string[] strArr = str.Split(' ');
  36. for (int j = 0; j < n; j++) {
  37. arr1[index, j] = Convert.ToInt32(strArr[j]);
  38. }
  39. }
  40. int k = Vestigium.getoutPut(arr1, n);
  41. int[] arr2 = new int[n];
  42. int r = 0;
  43. int c = 0;
  44. for (int i = 0; i < n; i++) {
  45. for (int j = 0; j < n; j++) {
  46. arr2[j] = arr1[i, j];
  47. }
  48. int check = Vestigium.countFreq(arr2, n);
  49. if (check > 0) { r += 1; }
  50. }
  51. for (int i = 0; i < n; i++) {
  52. for (int j = 0; j < n; j++) {
  53. arr2[j] = arr1[j, i];
  54. }
  55. int check = Vestigium.countFreq(arr2, n);
  56. if (check > 0) { c += 1; }
  57. }
  58. Console.WriteLine("Case #" + (tc + 1).ToString() + ": " + k.ToString() + " " + r.ToString() + " " + c.ToString());
  59. }
  60. }
  61. catch (Exception E) {
  62. Console.WriteLine(E.Message);
  63. }
  64. }
  65. }
  66.  
Success #stdin #stdout 0.03s 16340KB
stdin
3
4
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1
4
2 2 2 2
2 3 2 3
2 2 2 3
2 2 2 2
3
2 1 3
1 3 2
1 2 3
stdout
Case #1: 4 0 0
Case #2: 9 4 4
Case #3: 8 0 2