C#实现找二维数组中的鞍点

鞍点定义:该位置上的元素值在行中最大,在该列上最小

代码示例:

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();
        }
    }
}

运行截图:

原文地址:https://www.cnblogs.com/zyj3955/p/15410213.html