Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ElvesWrappingPaper
- {
- class Program
- {
- static void Main(string[] args)
- {
- //input file management
- int lineCounter = 0;
- string currentLine;
- int length = 0, width = 0, height = 0, totalSurfaceArea = 0, totalRibbonLength = 0;
- // Read the file and display it line by line.
- System.IO.StreamReader file = new System.IO.StreamReader("Input.txt");
- //process
- while ((currentLine = file.ReadLine()) != null)
- {
- //split values from the current line, assign them
- string[] values = currentLine.Split('x');
- length = Int32.Parse(values[0]);
- width = Int32.Parse(values[1]);
- height = Int32.Parse(values[2]);
- //find the area
- int currentBoxArea = (2 * length * width) + (2 * width * height) + (2 * height * length);
- //find the smallest side
- int[] min = { length * width, width * height, length * height };
- int currentBoxMin = min.Min();
- //find the smallest perimeter
- int[] ribbons = { 2 * length + 2 * width, 2 * width + 2 * height, 2 * height + 2 * length };
- int thisBoxRibbonPerimeter = ribbons.Min();
- //find the area
- int thisBoxRibbonArea = length * width * height;
- //Total up each box (these could be made into one line each, but I wanted to summarize each box)
- int thisBoxTotalRibbon = thisBoxRibbonPerimeter + thisBoxRibbonArea;
- totalRibbonLength += thisBoxTotalRibbon;
- int thisBoxTotal = currentBoxArea + currentBoxMin;
- totalSurfaceArea += thisBoxTotal;
- //summarize each box
- Console.WriteLine("BOX #:{0}\n--Length: {1}\n--Width: {2}\n--Height: {3}\n--Box area: {4}\n--Mininum area: {5}\n--Box Total Paper Requirement: {6}\n--Box Ribbon Length: {7}\n--Box Area: {8}\n--Box's Total Ribbon Requirement: {9}\n-----------", lineCounter+1, length, width, height, currentBoxArea, currentBoxMin, thisBoxTotal, thisBoxRibbonPerimeter, thisBoxRibbonArea, thisBoxTotalRibbon);
- lineCounter++;
- }
- //Display the total
- Console.WriteLine("Total Wrapping Paper Needed: {0}\n Total Ribbon Needed: {1}", totalSurfaceArea, totalRibbonLength);
- file.Close();
- // Suspend the screen.
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement