Advertisement
Guest User

FitBoxInBox

a guest
Mar 8th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class FitBoxInBox
  6. {
  7.     static void Main()
  8.     {
  9.         // initialize two lists of integer numbers, for the 3 dimention numbers per box: box1 and box2
  10.         List<int> box1 = new List<int>();
  11.  
  12.         // fill list box1 with values
  13.         for (int i = 0; i < 3; i++)
  14.         {
  15.             box1.Add(int.Parse(Console.ReadLine()));
  16.         }
  17.  
  18.         // fill list box2 with values
  19.         List<int> box2 = new List<int>();
  20.         for (int i = 0; i < 3; i++)
  21.         {
  22.             box2.Add(int.Parse(Console.ReadLine()));
  23.         }
  24.  
  25.         // compare box1 and box2 initial values, assuming that box1 is the smaller one
  26.         //Console.WriteLine(string.Join(" ", box2));
  27.         CompareBoxes(box1, box2);
  28.  
  29.         // start swapping second box values; if you uncomment the Console.WriteLine lines below, you will see how exactly the array looks like after each reversing
  30.         box2.Reverse(1, 2); // second and third value swap places: the code means: start at position 1 in the array, and swap 2 array elements
  31.         // in the above case this means: we have an array of 3 numbers, say 1 2 3, start at number 2 (position 1), and swap 2 numbers (numbers 2 and 3)
  32.         // the result is 1 3 2
  33.         CompareBoxes(box1, box2);
  34.         //Console.WriteLine(string.Join(" ", box2));
  35.  
  36.         box2.Reverse(); // this code reverses the entire array: the above 1 3 2 becomes 2 3 1
  37.         CompareBoxes(box1, box2);
  38.         //Console.WriteLine(string.Join(" ", box2));
  39.  
  40.         box2.Reverse(1, 2);
  41.         CompareBoxes(box1, box2);
  42.         //Console.WriteLine(string.Join(" ", box2));
  43.  
  44.         box2.Reverse();
  45.         CompareBoxes(box1, box2);
  46.         //Console.WriteLine(string.Join(" ", box2));
  47.  
  48.         box2.Reverse(1, 2);
  49.         CompareBoxes(box1, box2);
  50.         //Console.WriteLine(string.Join(" ", box2));
  51.  
  52.         box2.Reverse(); // to initial values
  53.         // compare box1 and box2 initial values, assuning that box2 is the smaller one
  54.         //Console.WriteLine(string.Join(" ", box1));
  55.         CompareBoxes(box2, box1); // as the method needs the box, assumed to be smaller, to be at first position, we swap the positions of box1 ans box2
  56.  
  57.  
  58.         // start swapping first box values
  59.         box1.Reverse(1, 2);
  60.         CompareBoxes(box2, box1);
  61.         //Console.WriteLine(string.Join(" ", box1));
  62.  
  63.         box1.Reverse();
  64.         CompareBoxes(box2, box1);
  65.         //Console.WriteLine(string.Join(" ", box1));
  66.  
  67.         box1.Reverse(1, 2);
  68.         CompareBoxes(box2, box1);
  69.         //Console.WriteLine(string.Join(" ", box1));
  70.  
  71.         box1.Reverse();
  72.         CompareBoxes(box2, box1);
  73.         //Console.WriteLine(string.Join(" ", box1));
  74.  
  75.         box1.Reverse(1, 2);
  76.         CompareBoxes(box2, box1);
  77.         //Console.WriteLine(string.Join(" ", box1));
  78.  
  79.     }
  80.     // this method compares the box assumed to be smaller to the box assumed to be bigger
  81.     // the numbers in the first array respectively correspond to the box assumed to be smaller
  82.     // the numbers in the second array correspond to the box assumed to be bigger
  83.     private static void CompareBoxes(List<int> first, List<int> second)
  84.     {
  85.         if (first[0] < second[0] && first[1] < second[1] && first[2] < second[2])
  86.         {
  87.             Console.WriteLine("({0}, {1}, {2}) < ({3}, {4}, {5})",
  88.                 first[0], first[1], first[2], second[0], second[1], second[2]);
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement