ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1618. Arrays Printing

The 2nd sample
Послано Zodiac 17 авг 2008 14:12
Why is the output 1?
I think there're also three configurations to achieve the string, just as the 3rd sample:

1. second = new Object[1][1][0];

2. Object level1 = new Object[1][0];
   second = new Object[] { level1 };

3. Object level2 = new Object[0];
   second = new Object[] { new Object[] { level2 }};

Could anyone explain why the above three configurations should be considered as one?
Re: The 2nd sample
Послано Denis Koshman 8 сен 2008 23:45
Because
A[0]==A[0] <=> B[0]==B[0] <=> C[0]==C[0]
and
A[0][0]==A[0][0] <=> B[0][0]==B[0][0] <=> C[0][0]==C[0][0] and
A[0][0][0]==A[0][0][0] <=> B[0][0][0]==B[0][0][0] <=> C[0][0][0]==C[0][0][0]

'<=>' means equality of its boolean operands.

'==' means 'equal-by-reference', i.e. they refer the same object. Objects are different if they were created by different 'new' statements or if they belong to different elements of the same 'new' statement. Assignments '=' during array creation modify references, but not objects. New objects are created only by 'new' statements. So, references within array are equal iff they trace back to the same element of the same 'new' statement. Otherwise they are different.

Edited by author 09.09.2008 01:33

Edited by author 09.09.2008 01:34