1294: 实验2-1-2 3x3 矩阵行列统计 / Row and Column Statistics of a 3x3 Matrix

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:117 Solved:84

Description

【中文题面】
输入一个 3x3 整数矩阵,统计每一行和每一列的元素和。
再找出行和最大的行、列和最大的列。若出现并列,选择编号较小的行或列。
[English Statement]
Given a 3x3 integer matrix, compute the sum of each row and each column.
Then find the row with the largest row sum and the column with the largest column sum. If there is a tie, choose the smaller index.
Only rows and columns are required. No diagonal output is needed. The focus is 2D arrays, nested loops, and clear row/column indices.

Input

【输入】
输入 3 行,每行 3 个整数,表示矩阵。
[Input]
The input contains 3 lines, each with 3 integers.

Output

【输出】
第一行输出 3 个行和。
第二行输出 3 个列和。
第三行输出行和最大的行号和对应行和,行号从 1 开始。
第四行输出列和最大的列号和对应列和,列号从 1 开始。
[Output]
Line 1: print the 3 row sums.
Line 2: print the 3 column sums.
Line 3: print the 1-based index of the row with the largest row sum and that sum.
Line 4: print the 1-based index of the column with the largest column sum and that sum.

Sample Input Copy

1 2 3
4 5 6
7 8 9

Sample Output Copy

6 15 24
12 15 18
3 24
3 18

HINT

【拓展练习与 AI 使用建议】
拓展练习:并列时改为选择编号较大的行或列;或把最大改为最小。
向 AI 提问时,要求只写 3x3 固定大小版本,不要写动态数组、vector、结构体或泛化到任意 n 的复杂程序。
读懂代码时重点检查两层循环中 i 表示行、j 表示列,列和是否写成了 a[i][j] 中固定 j、遍历 i。
[Extension and AI Advice]
Extension: when tied, choose the larger index; or find the minimum sum instead of the maximum.
When prompting AI, ask for a fixed 3x3 solution only. Avoid dynamic arrays, vector, structs, or a generalized n-by-n design.
When reading the code, check that i means row and j means column, and that column sums traverse i while keeping j fixed.