Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using System.Text;
- using System.Threading.Tasks;
- namespace Cau1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] a = input();
- //output(a);
- //Console.WriteLine(totalColumn(a, 2));
- //Console.WriteLine(totalMaxColumn(a));
- List<int> b = timHoanHao(a);
- foreach (int item in b)
- {
- Console.WriteLine(item);
- }
- }
- public static List<int> timHoanHao(int[,] a)
- {
- List<int> res = new List<int>();
- for (int i = 0; i < a.GetLength(0); i++)
- {
- for (int j = 0; j < a.GetLength(1); j++)
- {
- if (kiemTraHoanHao(a[i, j])) res.Add(a[i, j]);
- }
- }
- return res;
- }
- public static bool kiemTraHoanHao(int a)
- {
- int total = 0;
- if (a == 0) return false;
- for (int i = 1; i < a; i++)
- {
- if (a % i == 0) total += i;
- }
- return total == a;
- }
- public static int totalMaxColumn(int[,] a)
- {
- int max = 0;
- int column = 0;
- for (int j = 0; j < a.GetLength(1); j++)
- {
- int temp = 0;
- for (int i = 0; i < a.GetLength(0); i++)
- {
- temp += a[i, j];
- }
- if (max < temp)
- {
- max = temp;
- column = j;
- }
- }
- return column;
- }
- public static int totalColumn(int[, ] a, int k)
- {
- int total = 0;
- for (int i = 0; i < a.GetLength(0); i++)
- {
- for (int j = 0; j < a.GetLength(1); j++)
- {
- if (j == k) total += a[i, j];
- }
- }
- return total;
- }
- public static int[,] input()
- {
- int m = 0, n = 0;
- do
- {
- m = int.Parse(Console.ReadLine());
- } while (m < 1 || m > 100);
- do
- {
- n = int.Parse(Console.ReadLine());
- } while (n < 1 || n > 100);
- int[,] a = new int[m, n];
- for (int i = 0; i < m; i++)
- {
- string[] temp = Console.ReadLine().Split();
- for (int j = 0; j < n; j++)
- {
- a[i, j] = int.Parse(temp[j]);
- }
- }
- return a;
- }
- public static void output(int[,] a)
- {
- for (int i = 0; i < a.GetLength(0); i++)
- {
- for (int j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement