MuffinMonster

Class Task 54#

Feb 28th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication2
  7. {
  8.     class Program
  9.     {
  10.         static bool Dlila(int[,] matrix, int total)
  11.         {
  12.             bool ok = true;
  13.             double avg;
  14.             int counterperline;
  15.             int counterall = 0;
  16.             for (int i = 0; i < matrix.GetLength(0); i++)
  17.             {
  18.                 counterperline = 0;
  19.                 for (int j = 0; j < matrix.GetLength(1); j++)
  20.                 {
  21.                     if (matrix[i, j] != 0)
  22.                     {
  23.                         counterall++;
  24.                         counterperline++;
  25.                     }
  26.                 }
  27.                 if (counterperline > 2)
  28.                     ok = false;
  29.             }
  30.             avg = (double)total * 0.2;
  31.             if (counterall > avg)
  32.                 ok = false;
  33.             return ok;
  34.         }
  35.         static void Main(string[] args)
  36.         {
  37.             Console.Write("Size of the matrix: ");
  38.             int n = int.Parse(Console.ReadLine());
  39.             int[,] matrix = new int[n, n];
  40.             Random R = new Random();
  41.             for (int i = 0; i < matrix.GetLength(0); i++)
  42.             {
  43.                 for (int j = 0; j < matrix.GetLength(1); j++)
  44.                 {
  45.                    
  46.                     matrix[i, j] = int.Parse(Console.ReadLine());
  47.                 }
  48.                 Console.WriteLine();
  49.             }
  50.             bool ok = Dlila(matrix, (n * n));
  51.             Console.Write(ok);
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment