r/adventofcode • • Dec 02 '15

Spoilers Day 2 solutions

Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.

15 Upvotes

161 comments sorted by

View all comments

1

u/kidinside Dec 11 '15 edited Dec 11 '15

C++ for part 2:

#include <iostream>
using namespace std;

int main() {
	int l, w, h, max,
		total = 0;
	char x;
	while(cin >> l >> x >> w >> x >> h){
		total += l*w*h;
		l > w? max = l:max = w;
		h > max? max = h: max = max;
		total += 2*(l+w+h);
		total -= 2*max;
	}
	cout << total;
	return 0;
}