top1编程
← 返回题目
题解

【入门】求矩阵最大值

1 条题解

  • 0
    @ 2026-7-28 22:10:11
    #include <bits/stdc++.h>
    using namespace std;
    
    int a[3][4];
    
    int main()
    {
    	for(int i = 1; i <= 3; i++)
    	{
    		for(int j = 1; j <= 4; j++)
    		{
    			cin >> a[i][j];
    		}
    	}
    	int max = a[1][1];
    	int x = 0, y = 0;
    	for(int i = 1; i <= 3; i++)
    	{
    		for(int j = 1; j <= 4; j++)
    		{
    			if(a[i][j] > max)
    			{
    				max = a[i][j];
    				x = i;
    				y = j;
    			}
    		}
    	}
    	cout << max << endl;
    	cout << x << endl;
    	cout << y << endl;
    	return 0;
    }
    
    • 1