Олимпиадный тренинг

Задача . 37387


Задача

Темы:
Consider a class MatrixStuff that has a private instance variable:
private int[][] mat;
Refer to method alter below that occurs in the MatrixStuff class. (The lines are numbered for reference.)
Line 1: /** @param mat the matrix initialized with integers
Line 2: * @param c the column to be removed
Line 3: * Postcondition:
Line 4: * - Column c has been removed.
Line 5: * - The last column is filled with zeros.
Line 6: */
Line 7: public void alter(int[][] mat, int c)
Line 8: {
Line 9:     for (int i = 0; i < mat.length; i++)
Line 10:        for (int j = c; j < mat[0].length; j++)
Line 11:            mat[i][j] = mat[i][j+1];
Line 12:     //code to insert zeros in rightmost column
Line 13:            ...
Line 14: }
The intent of the method alter is to remove column c. Thus, if the input matrix mat is
2 6 8 9
1 5 4 3
0 7 3 2
the method call alter(mat, 1) should change mat to 
2 8 9 0
1 4 3 0
0 3 2 0
The method does not work as intended. Which of the following changes will correct the problem?

I Change line 10 to
for (int j = c; j < mat[0].length - 1; j++)
and make no other changes.

II Change lines 10 and 11 to
for (int j = c + 1; j < mat[0].length; j++)
    mat[i][j-1] = mat[i][j];
and make no other changes.

III Change lines 10 and 11 to
for (int j = mat[0].length - 1; j > c; j--)
    mat[i][j-1] = mat[i][j];
and make no other changes.

(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя