summaryrefslogtreecommitdiffstats
path: root/solutions/c/01-2.cpp
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:02:31 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:02:31 +0100
commit831755fdc6d430bd8781da1897270cf2934bc858 (patch)
treef1d6e5609363f98534a87eb9203a7623fb409371 /solutions/c/01-2.cpp
downloadaoc-831755fdc6d430bd8781da1897270cf2934bc858.tar.gz
Initial commit
Diffstat (limited to 'solutions/c/01-2.cpp')
-rw-r--r--solutions/c/01-2.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/solutions/c/01-2.cpp b/solutions/c/01-2.cpp
new file mode 100644
index 0000000..7ce1a82
--- /dev/null
+++ b/solutions/c/01-2.cpp
@@ -0,0 +1,14 @@
+#include<iostream>
+
+int getFuel(int mass) {
+ int fuel = (mass / 3) - 2;
+ if (fuel <= 0) return 0;
+ return fuel + getFuel(fuel);
+}
+
+int main() {
+ int mass, sum = 0;
+ while (std::cin >> mass) sum += getFuel(mass);
+ std::cout << sum << std::endl;
+}
+