MuffinMonster

Class Task 51#

Feb 19th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Insert(int[,] arr)
  11.         {
  12.             for (int i = 0; i < arr.GetLength(0); i++)
  13.             {
  14.                 for (int j = 0; j < arr.GetLength(1); j++)
  15.                 {
  16.                     Console.Write(i + " " + j + ": ");
  17.                     arr[i, j] = int.Parse(Console.ReadLine());
  18.                 }
  19.             }
  20.         }
  21.         static bool Check(int[,] arr)
  22.         {
  23.             bool ok = true;
  24.             int length = 0;
  25.             int tempcount = 0;
  26.             for (int j = 0; j < arr.GetLength(1); j++)
  27.             {
  28.                 length += arr[0, j];
  29.             }
  30.             for (int i = 0; i < arr.GetLength(0); i++)
  31.             {
  32.                 for (int j = 0; j < arr.GetLength(1); j++)
  33.                     {
  34.                         tempcount += arr[i, j];
  35.                     }
  36.                     if (tempcount != length)
  37.                         ok = false;
  38.                     tempcount = 0;
  39.                 }
  40.             for (int j = 0; j < arr.GetLength(1); j++)
  41.             {
  42.                 for (int i = 0; i < arr.GetLength(0); i++)
  43.                 {
  44.                     tempcount += arr[i, j];
  45.                 }
  46.                 if (tempcount != length)
  47.                     ok = false;
  48.                 tempcount = 0;
  49.             }
  50.             /////////////
  51.                 int var = 0;
  52.                 for (int j = 0; j < arr.GetLength(0); j++)
  53.                 {
  54.                     tempcount += arr[var, j];
  55.                     var++;
  56.                 }
  57.                 if (tempcount != length)
  58.                     ok = false;
  59.                 tempcount = 0;
  60.                 var = arr.GetLength(1)-1;
  61.                 for (int i = 0; i < arr.GetLength(0); i++)
  62.                 {
  63.                     tempcount += arr[i, var];
  64.                     var--;
  65.                 }
  66.                 if (tempcount != length)
  67.                     ok = false;
  68.                 tempcount = 0;
  69.             return ok;
  70.         }
  71.         static void Main(string[] args)
  72.         {
  73.             int a = int.Parse(Console.ReadLine());
  74.             int[,] square = new int[a, a];
  75.             Insert(square);
  76.             Console.Clear();
  77.             bool check = Check(square);
  78.             Console.WriteLine(check);
  79.             Console.ReadKey();
  80.         }
  81.     }
  82. }
Add Comment
Please, Sign In to add comment