Advertisement
mustafov

Fit Box in Box

Sep 3rd, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.14 KB | None | 0 0
  1. // Fit Box in Box
  2. //Nakov likes boxes. Ha has many boxes at home. To save space he often puts his boxes one inside another. A box can fit inside //another box if the size of the smaller box is smaller than the size of the bigger box in all dimensions at the same time. Of //course, boxes can be rotated to fit one inside another. Here are few examples:
  3. //•   (5, 1, 6) fits naturally in (6, 2, 9), because 5 < 6 and 1 < 2 and 6 < 9
  4. //•   (5, 1, 6) fits in (2, 7, 6) after rotating the second box to (6, 2, 7)
  5. //•   (7, 8, 1) cannot fit in (12, 7, 3) even after rotating
  6. //•   (6, 2, 9) cannot fit in (5, 1, 6) even after rotating
  7. //You are given the sizes of two boxes (width, height and depth). Write a program to check whether the boxes can fit one inside //another and how exactly. Print the smaller box first, exactly as it is given in the input (without rotating), followed by "<" and //the larger box (eventually rotated) to fit each of the dimensions. Print all possible ways to put the smaller box into the larger //box. In case there is no smaller box, print nothing. See the examples below to catch the idea.
  8.  
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15.  
  16. namespace FitBoxInBox
  17. {
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             int w1 = int.Parse(Console.ReadLine());
  23.             int h1 = int.Parse(Console.ReadLine());
  24.             int d1 = int.Parse(Console.ReadLine());
  25.             int w2 = int.Parse(Console.ReadLine());
  26.             int h2 = int.Parse(Console.ReadLine());
  27.             int d2 = int.Parse(Console.ReadLine());
  28.             int firstBoxBigger = w1 + h1 + d1;
  29.             int secondBoxBigger = w2 + h2 + d2;
  30.             if (firstBoxBigger > secondBoxBigger)
  31.             {
  32.                 if (w2 < w1 && h2 < h1 && d2 < d1)
  33.                 {
  34.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})",w2,h2,d2,w1,h1,d1);
  35.                 }
  36.                 if (w2 < w1 && h2 < d1 && d2 < h1)
  37.                 {
  38.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w2, h2, d2, w1, d1, h1);
  39.                 }
  40.                 if (w2 < h1 && h2 < w1 && d2 < d1)
  41.                 {
  42.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w2, h2, d2, h1, w1, d1);
  43.                 }
  44.                 if (w2 < h1 && h2 < d1 && d2 < w1)
  45.                 {
  46.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w2, h2, d2, h1, d1, w1);
  47.                 }
  48.                 if (w2 < d1 && h2 < w1 && d2 < h1)
  49.                 {
  50.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w2, h2, d2, d1, w1, h1);
  51.                 }
  52.                 if (w2 < d1 && h2 < h1 && d2 < w1)
  53.                 {
  54.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w2, h2, d2, d1, h1, w1);
  55.                 }
  56.             }
  57.  
  58.             if (firstBoxBigger < secondBoxBigger)
  59.             {
  60.                 if (w1 < w2 && h1 < h2 && d1 < d2)
  61.                 {
  62.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, w2, h2, d2);
  63.                 }
  64.                 if (w1 < w2 && h1 < d2 && d1 < h2)
  65.                 {
  66.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, w2, d2, h2);
  67.                 }
  68.                 if (w1 < h2 && h1 < w2 && d1 < d2)
  69.                 {
  70.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, h2, w2, d2);
  71.                 }
  72.                 if (w1 < h2 && h1 < d2 && d1 < w2)
  73.                 {
  74.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, h2, d2, w2);
  75.                 }
  76.                 if (w1 < d2 && h1 < w2 && d1 < h2)
  77.                 {
  78.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, d2, w2, h2);
  79.                 }
  80.                 if (w1 < d2 && h1 < h2 && d1 < w2)
  81.                 {
  82.                     Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})", w1, h1, d1, d2, h2, w2);
  83.                 }
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement