svetlozar_kirkov

Fit Box in Box

Sep 8th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace FitBoxInBox
  7. {
  8.     class FitBoxInBox
  9.     {
  10.         static void Main()
  11.         {
  12.             List<int> boxOne = new List<int>();
  13.             List<int> boxTwo = new List<int>();
  14.             List<int> big = new List<int>();
  15.             List<int> small = new List<int>();
  16.  
  17.             for (int i = 0; i < 3; i++)
  18.             {
  19.                 boxOne.Add(int.Parse(Console.ReadLine()));
  20.             }
  21.  
  22.             for (int i = 0; i < 3; i++)
  23.             {
  24.                 boxTwo.Add(int.Parse(Console.ReadLine()));
  25.             }
  26.  
  27.             int boxOneVol = boxOne[0] * boxOne[1] * boxOne[2];
  28.             int boxTwoVol = boxTwo[0] * boxTwo[1] * boxTwo[2];
  29.  
  30.             if (boxOneVol > boxTwoVol)
  31.             {
  32.                 big = boxOne.ToList();
  33.                 small = boxTwo.ToList();
  34.             }
  35.             else if (boxOneVol < boxTwoVol)
  36.             {
  37.                 big = boxTwo.ToList();
  38.                 small = boxOne.ToList();
  39.             }
  40.             else
  41.             {
  42.                 return;
  43.             }
  44.  
  45.             if (big.Min() <= small.Min())
  46.             {
  47.                 return;
  48.             }
  49.             else
  50.             {
  51.                 foreach (var permu in Permutate(big, big.Count))
  52.                 {
  53.                     List<int> temp = new List<int>();
  54.                     foreach (var i in permu)
  55.                     {
  56.                         temp.Add(Convert.ToInt32(i));
  57.                     }
  58.  
  59.                     if (temp[0] > small[0] && temp[1] > small[1] && temp[2] > small[2])
  60.                     {
  61.                         Console.WriteLine("(" + small[0] + ", " + small [1] + ", " + small[2] + ")" + " < " +
  62.                             "(" + permu[0] + ", " + permu[1] + ", " + permu[2] + ")");
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.         public static void RotateRight(IList sequence, int count)
  68.         {
  69.             object tmp = sequence[count - 1];
  70.             sequence.RemoveAt(count - 1);
  71.             sequence.Insert(0, tmp);
  72.         }
  73.  
  74.         public static IEnumerable<IList> Permutate(IList sequence, int count)
  75.         {
  76.             if (count == 1) yield return sequence;
  77.             else
  78.             {
  79.                 for (int i = 0; i < count; i++)
  80.                 {
  81.                     foreach (var perm in Permutate(sequence, count - 1))
  82.                         yield return perm;
  83.                    
  84.                     if (true)
  85.                     {
  86.                        
  87.                     }
  88.                     RotateRight(sequence, count);
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment