鞍點定義:該位置上的元素值在行中最大,在該列上最小
代碼示例:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NET_test1_5 { class Program { static void Main(string[] args) { int z=0; Console.WriteLine("請輸入數組的行數和列數"); int row = int.Parse(Console.ReadLine()); int column = int.Parse(Console.ReadLine()); int[,] a=new int[row,column]; Console.WriteLine("請輸入二維數組的值:"); //輸入二維數組 for (int x = 0; x < row; x++) { for (int y = 0; y < column; y++) { a[x, y] = int.Parse(Console.ReadLine()); } } //輸出二維數組 Console.WriteLine("二維數組為:"); for (int x = 0; x < row; x++) { Console.WriteLine(); for (int y = 0; y < column; y++) { Console.Write(a[x, y]+" "); } } //找鞍點 Console.WriteLine(); //換行 for(int x=0;x<row;x++) { int max = a[x,0]; for(int y=0;y<column;y++) { if(max < a[x,y]) max = a[x,y]; z = y; } int min = a[0,z]; for(int y=0;y<row;y++) { if(min > a[x,z]) min = a[x,z]; } if(min == max ) { Console.WriteLine("該二維數組的鞍點為:"+max); } } Console.ReadKey(); } } }
運行截圖: