ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1618. Arrays Printing

The 2nd sample
Posted by Zodiac 17 Aug 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
Posted by Denis Koshman 8 Sep 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