Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp9
- {
- public class Village
- {
- public Random rnd = new Random();
- int x;
- int[,] arr;
- public Village()
- {
- Console.Write("enter the size of the array:");
- x = int.Parse(Console.ReadLine());
- arr = new int[x, x];
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < x; j++)
- {
- if (arr[i, j] == 0)
- {
- if (i == j)
- {
- arr[i, j] = 0;
- }
- else
- {
- //Console.WriteLine("enter the distance between village{0} an village{1}:", i, j);
- int RandomNumber = rnd.Next(1, 100);
- arr[i, j] = arr[j, i] = RandomNumber;
- }
- }
- }
- }
- }
- public void print()
- {
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < x; j++)
- {
- Console.Write("{0,5}", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- public int findVillage()
- {
- int min = int.MaxValue;
- int minVillage=-1;
- for (int v = 0; v < x; v++)
- {
- int max = 0;
- int maxVillage = 0;
- for (int i = 0; i < x; i++)
- {
- if (arr[v, i] > max) { max = arr[v, i];maxVillage = i; }
- }
- Console.WriteLine(max+":"+ maxVillage);
- if (max < min)
- {
- min = max;
- minVillage = v;
- }
- }
- Console.WriteLine(min+" : "+minVillage);
- return minVillage;
- }
- static void Main(string[] args)
- {
- Village v = new Village();
- v.print();
- int t=v.findVillage();
- Console.WriteLine("place the station in village number {0}",t);
- //AvgOfStudents();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement