All pastes #918414 Raw Edit

Untitled

public text v1 · immutable
#918414 ·published 2008-02-26 02:46 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace S2
{
	class Program
	{
		public class Box
		{
			public int[] dimensions;

			public Box(int x, int y, int z)
			{
				dimensions = new int[3];
				dimensions[0] = x;
				dimensions[1] = y;
				dimensions[2] = z;
			}
		}

		static List<Box> boxes = new List<Box>();

		static void Main(string[] args)
		{
			int times;
			times = int.Parse(Console.ReadLine());
			for (int i = 0; i < times; i++) {
				string[] dimensions = Console.ReadLine().Split(' ');
				boxes.Add(new Box(int.Parse(dimensions[0]), int.Parse(dimensions[1]), int.Parse(dimensions[2])));
			}

			times = int.Parse(Console.ReadLine());
			for (int i = 0; i < times; i++) {
				string[] dimensions = Console.ReadLine().Split(' ');
				Box item = new Box(int.Parse(dimensions[0]), int.Parse(dimensions[1]), int.Parse(dimensions[2]));
				Box box = GetBox(item);
				if (box == null)
					Console.WriteLine("Item does not fit.");
				else {
					Console.WriteLine(box.dimensions[0] * box.dimensions[1] * box.dimensions[2]);
				}
			}
		}

		static Box GetBox(Box item)
		{
			foreach (Box box in boxes) {
				if (DimensionsMatch(box.dimensions, item.dimensions))
					return box;
			}

			return null;
		}

		static bool DimensionsMatch(int[] d1, int[] d2)
		{
			bool match = false;

			foreach (int d in d1) {
				match = false;
				foreach (int dd in d2) {
					if (d >= dd)
						match = true;
				}

				if (!match)
					return false;
			}

			return true;
		}
	}
}