zoukankan      html  css  js  c++  java
  • 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();
            }
        }
    }

    运行截图:

  • 相关阅读:
    servlet中如何实现通过Spring实现对象的注入
    异步Socket
    JAVA NIO实现
    【Java并发】
    JAVA实现阻塞队列
    lock与synchronized比较
    线程执行顺序
    ConcurrentHashMap 1.8
    LeetCode 416 分割等和子集
    linux常用指令
  • 原文地址:https://www.cnblogs.com/zyj3955/p/15410213.html
Copyright © 2011-2022 走看看