Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Boxes
10-05-2009, 07:53 PM (This post was last modified: 10-06-2009 12:05 AM by XIO-X2.)
Post: #1
Boxes
You know the height, the width and the length of two boxes. You have to check if one box can be put inside the other one. In other words, can you rotate one of the boxes so that it can be put into the other one.

INPUT:
You should read the input from the standard input. From the first line read three integers d1, s1 i v1 - height, width and length of the first box. From the second line read another three integers d2, s2 i v2, height, width and length of the second box. All dimensions are less than 1000.

OUTPUT:
To the standard output write "DA" (without quotes), if one box can be put into the other one. Otherwise output "NE".



Code:
1.
      var
   2.
      i : integer;
   3.
      j : integer;
   4.
      L : Integer;
   5.
      D : Integer;
   6.
      P : integer;
   7.
      A : array [1..3] of integer;
   8.
      B : array [1..3] of integer;
   9.
      bOk : Boolean;
  10.
      BEGIN
  11.
        For i := 1 to 3 Do  Read ( a[i] );
  12.
        For i := 1 to 3 Do  Read ( b[i] );
  13.
      
  14.
        For L := 1 To 2 Do
  15.
        For D := L + 1 To 3 Do
  16.
            If A [ L ] < A [ D ]
  17.
            Then
  18.
               Begin
  19.
                  P       := A [ L ];
  20.
                  A [ L ] := A [ D ];
  21.
                  A [ D ] := P;
  22.
               End;
  23.
      
  24.
        For L := 1 To 2 Do
  25.
        For D := L + 1 To 3 Do
  26.
            If B [ L ] < B [ D ]
  27.
            Then
  28.
               Begin
  29.
                  P       := B [ L ];
  30.
                  B [ L ] := B [ D ];
  31.
                  B [ D ] := P;
  32.
               End;
  33.
      
  34.
      
  35.
        bOk := True;
  36.
        If ( A [1] > b[1]) and (a[2] > b[2]) and (a[3] > b[3])
  37.
        then
  38.
          bOk := True
  39.
        Else
  40.
          bOk := False;
  41.
      
  42.
        If not bOk
  43.
        Then
  44.
          If (b[1] > a[1]) and (b[2] > a[2]) and (b[3] > a[3]) then
  45.
           bOk := True;
  46.
      
  47.
        If bOk
  48.
        Then
  49.
           Writeln ('DA')
  50.
        Else
  51.
           Writeln ('NE')
  52.
      
  53.
      END.

Read rules Smile
[Image: legislator.png]
Find all posts by this user
Quote this message in a reply
10-05-2009, 10:00 PM
Post: #2
RE: Boxes
I can say this is really interesting !
I would make mistake in this, i would only check if a1>a2 and b1>b2 and c1>c2, but this about sorting, it is really good idea. Great solution.
For those who doesn't know a lot about sorting, you have it here :
http://www.pro9ramming.com/algorithm-for...g-t-4.html

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
10-06-2009, 02:38 AM
Post: #3
RE: Boxes
Thanks, this is my work from practice for last competition Smile

Read rules Smile
[Image: legislator.png]
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: