Advertisement
mmayoub

kamal

Oct 26th, 2021
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp9
  4. {
  5.     public class Village
  6.     {
  7.         public Random rnd = new Random();
  8.         int x;
  9.         int[,] arr;
  10.         public Village()
  11.         {
  12.             Console.Write("enter the size of the array:");
  13.             x = int.Parse(Console.ReadLine());
  14.             arr = new int[x, x];
  15.  
  16.             for (int i = 0; i < x; i++)
  17.             {
  18.                 for (int j = 0; j < x; j++)
  19.                 {
  20.                     if (arr[i, j] == 0)
  21.                     {
  22.                         if (i == j)
  23.                         {
  24.                             arr[i, j] = 0;
  25.                         }
  26.                         else
  27.                         {
  28.                             //Console.WriteLine("enter the distance between village{0} an village{1}:", i, j);
  29.                             int RandomNumber = rnd.Next(1, 100);
  30.                             arr[i, j] = arr[j, i] = RandomNumber;
  31.                         }
  32.                     }
  33.  
  34.                 }
  35.  
  36.             }
  37.         }
  38.         public void print()
  39.         {
  40.             for (int i = 0; i < x; i++)
  41.             {
  42.                 for (int j = 0; j < x; j++)
  43.                 {
  44.                     Console.Write("{0,5}", arr[i, j]);
  45.                 }
  46.                 Console.WriteLine();
  47.  
  48.             }
  49.  
  50.         }
  51.  
  52.         public int findVillage()
  53.         {
  54.             int min = int.MaxValue;
  55.             int minVillage=-1;
  56.  
  57.             for (int v = 0; v < x; v++)
  58.             {
  59.  
  60.                 int max = 0;
  61.                 int maxVillage = 0;
  62.                 for (int i = 0; i < x; i++)
  63.                 {
  64.                     if (arr[v, i] > max) { max = arr[v, i];maxVillage = i; }
  65.                 }
  66.                 Console.WriteLine(max+":"+ maxVillage);
  67.  
  68.                 if (max < min)
  69.                 {
  70.                     min = max;
  71.                     minVillage = v;
  72.                 }
  73.  
  74.             }
  75.  
  76.             Console.WriteLine(min+" : "+minVillage);
  77.             return minVillage;
  78.         }
  79.         static void Main(string[] args)
  80.         {
  81.             Village v = new Village();
  82.             v.print();
  83.             int t=v.findVillage();
  84.             Console.WriteLine("place the station in village number {0}",t);
  85.             //AvgOfStudents();
  86.         }
  87.     }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement