1 using System;
 2 using System.Collections.Generic;
 3 
 4 namespace Test_1_5
 5 {
 6     class Program
 7     {
 8         static void Main(string[] args)
 9         {
10             int max, min, rowindex=0,colindex=0, flag = 0;
11 
12             Console.WriteLine("选择数组的行数:");
13             string input1 = Console.ReadLine();
14             int data1 = Convert.ToInt32(input1);
15 
16             Console.WriteLine("选择数组的列数:");
17             string input2 = Console.ReadLine();
18             int data2 = Convert.ToInt32(input2);
19 
20         xunhuan:
21             Console.WriteLine("请输入{0}行{1}列的数组,空格分隔",data1, data2);
22             int[,] a = new int[data1, data2];
23                 for (int i = 0; i < data1; i++)
24                 {
25                     string str = Console.ReadLine();//首先输入一字符串,表示二维数组的一行数据
26                     string[] tmp = str.Split("".ToCharArray());//通过Split方法以空格作为分隔符将输入的一行字符串分开
27                     for (int j = 0; j < data2; j++)
28                     {
29                         if (tmp.Length != data2)
30                         {
31                         Console.WriteLine("输入格式有误");
32                         goto xunhuan;
33                         }
34                         else
35                         {
36                         a[i, j] = int.Parse(tmp[j]);//将分割后的字符赋值给二维数组的每个元素
37                         }
38                     }
39                 }
40 
41             Console.WriteLine("二维数组为:");
42             for(int i = 0; i < data1; i++)
43             {
44                 for(int j = 0; j < data2; j++)
45                 {
46                     Console.Write(a[i, j] + "  ");
47                 }
48                 Console.WriteLine();
49             }
50 
51             for(int i= 0; i < data1; ++i)
52             {
53                 //找到i行上最大的元素,记录该元素所在的列号colindex
54                 max = a[i, 0];
55                 for(int j = 0; j < data2; ++j)
56                 {
57                     if (a[i, j] > max)
58                     {
59                         max = a[i, j];
60                         colindex = j;
61                     }
62                 }
63                 min = a[0, colindex];
64                 //找max所在列上最小元素,记录所在行rowindex
65                 for (int j = 0; j < data1; ++j)
66                 {
67                     if (a[j, colindex] < min)
68                     {
69                         min = a[j, colindex];
70                         rowindex = j;
71                     }
72                 }
73                 if (max == min && i == rowindex)
74                 {
75                     flag = 1;
76                     Console.WriteLine("鞍点为{0}行{1}列的元素{2}", rowindex+1, colindex+1, max);
77                     break;
78 
79                 }
80             }
81             if (0 == flag)
82             {
83                 Console.WriteLine("没有鞍点");
84             }
85 
86         }
87     }
88 }

截图

 

 

 

Copyright © 2024 ***Pepsi***
Powered by .NET 8.0 on Kubernetes