Advertisement
vovanhoangtuan

KiẻmTra

Jul 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices.WindowsRuntime;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Cau1
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int[,] a = input();
  15. //output(a);
  16. //Console.WriteLine(totalColumn(a, 2));
  17. //Console.WriteLine(totalMaxColumn(a));
  18.  
  19. List<int> b = timHoanHao(a);
  20. foreach (int item in b)
  21. {
  22. Console.WriteLine(item);
  23. }
  24. }
  25.  
  26.  
  27. public static List<int> timHoanHao(int[,] a)
  28. {
  29. List<int> res = new List<int>();
  30.  
  31. for (int i = 0; i < a.GetLength(0); i++)
  32. {
  33. for (int j = 0; j < a.GetLength(1); j++)
  34. {
  35. if (kiemTraHoanHao(a[i, j])) res.Add(a[i, j]);
  36. }
  37.  
  38. }
  39. return res;
  40. }
  41.  
  42. public static bool kiemTraHoanHao(int a)
  43. {
  44. int total = 0;
  45. if (a == 0) return false;
  46. for (int i = 1; i < a; i++)
  47. {
  48. if (a % i == 0) total += i;
  49. }
  50.  
  51. return total == a;
  52. }
  53.  
  54. public static int totalMaxColumn(int[,] a)
  55. {
  56. int max = 0;
  57. int column = 0;
  58. for (int j = 0; j < a.GetLength(1); j++)
  59. {
  60. int temp = 0;
  61. for (int i = 0; i < a.GetLength(0); i++)
  62. {
  63. temp += a[i, j];
  64. }
  65. if (max < temp)
  66. {
  67. max = temp;
  68. column = j;
  69. }
  70. }
  71.  
  72. return column;
  73. }
  74.  
  75. public static int totalColumn(int[, ] a, int k)
  76. {
  77. int total = 0;
  78.  
  79. for (int i = 0; i < a.GetLength(0); i++)
  80. {
  81. for (int j = 0; j < a.GetLength(1); j++)
  82. {
  83. if (j == k) total += a[i, j];
  84. }
  85. }
  86.  
  87. return total;
  88. }
  89.  
  90. public static int[,] input()
  91. {
  92.  
  93. int m = 0, n = 0;
  94. do
  95. {
  96. m = int.Parse(Console.ReadLine());
  97. } while (m < 1 || m > 100);
  98.  
  99. do
  100. {
  101. n = int.Parse(Console.ReadLine());
  102. } while (n < 1 || n > 100);
  103.  
  104. int[,] a = new int[m, n];
  105. for (int i = 0; i < m; i++)
  106. {
  107. string[] temp = Console.ReadLine().Split();
  108. for (int j = 0; j < n; j++)
  109. {
  110. a[i, j] = int.Parse(temp[j]);
  111. }
  112. }
  113. return a;
  114. }
  115.  
  116. public static void output(int[,] a)
  117. {
  118. for (int i = 0; i < a.GetLength(0); i++)
  119. {
  120. for (int j = 0; j < a.GetLength(1); j++)
  121. {
  122. Console.Write(a[i, j] + " ");
  123. }
  124. Console.WriteLine();
  125. }
  126. }
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement