C: 2015 Day 2 Complete

This commit is contained in:
Brian Buller 2018-03-16 11:06:54 -05:00
parent 5885dced39
commit 7241b745b2

View File

@ -1,32 +1,58 @@
#include <stdio.h>
int getBoxArea(int l, int w, int h) {
int getBoxSidesArea(int l, int w, int h) {
return (2*l*w + 2*w*h + 2*h*l);
}
int getSmallestSide(int l, int w, int h) {
if(l < w && l < h) {
return l;
int getSmallestSideArea(int l, int w, int h) {
int smallest = (l * w);
if((l * h) < smallest) {
smallest = (l * h);
}
if(w < l && w < h) {
return w;
if((w * h) < smallest) {
smallest = (w * h);
}
return h;
return smallest;
}
int getSmallestPerimeter(int l, int w, int h) {
int use1, use2;
if(l < w || l < h) {
use1 = l;
if(w < h) {
use2 = w;
} else {
use2 = h;
}
} else {
use1 = w;
use2 = h;
}
return (use1 * 2) + (use2 * 2);
}
int getBoxArea(int l, int w, int h) {
return l * w * h;
}
void part1() {
printf("Part 1\n");
int floor = 0;
char str[100];
int l, w, h, result = 0;
while(scanf("%dx%dx%d", &l, &w, &h) > 0) {
result += getBoxArea(l, w, h) + getSmallestSide(l, w, h);
result += getBoxSidesArea(l, w, h) + getSmallestSideArea(l, w, h);
}
printf("Square Feet Needed: %d\n", result);
}
void part2() {
printf("Part 1\n");
printf("Part 2\n");
char str[100];
int l, w, h, result = 0;
while(scanf("%dx%dx%d", &l, &w, &h) > 0) {
result += getSmallestPerimeter(l, w, h) + getBoxArea(l, w, h);
}
printf("Ribbon Length Needed: %d\n", result);
}
int main(int argc, char **argv) {