Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Homeworks / homework1.cpp
diff options
context:
space:
mode:
1 files changed, 69 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Homeworks/homework1.cpp69
diff --git a/Year 1/Programming introduction/Homeworks/homework1.cpp b/Year 1/Programming introduction/Homeworks/homework1.cpp
new file mode 100644
index 0000000..8a06baf
--- /dev/null
+++ b/Year 1/Programming introduction/Homeworks/homework1.cpp
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <cmath>
+
+using namespace std;
+
+/*
+ * Exercise 1
+ */
+
+double f(unsigned int k, int x) {
+ if (k == 1) return x;
+
+ if (k & 1)
+ return 3 * f(k - 1, x) + 1;
+ return f(k - 1, x) / 2;
+}
+
+void ex1() {
+ int x;
+ cin >> x;
+
+ cout << f(35, x) << endl;
+}
+
+/*
+ * Exercise 2
+ */
+
+void setMarmaladeType(int type, int *blueberryMarmalades, int *peachMarmalades, int *rosehipMarmalades) {
+ if (type % 7 == 0) *blueberryMarmalades += 1;
+ else if (type % 13 == 0) *peachMarmalades += 1;
+ else if (type % 17 == 0) *rosehipMarmalades += 1;
+}
+
+void ex2() {
+ int archiveLength;
+ cin >> archiveLength;
+
+ int blueberryMarmalades = 0, peachMarmalades = 0, rosehipMarmalades = 0;
+
+ for (int i = 0, digit, countryDigits, typeDigits, type; i < archiveLength; i++) {
+ cin >> digit;
+ cout << digit;
+
+ if (i % 8 == 0) {
+ countryDigits = 1;
+ typeDigits = type = 0;
+ }
+ else if (countryDigits < 3) {
+ countryDigits++;
+ }
+ else if (typeDigits < 4) {
+ typeDigits++;
+ (type *= 10) += digit;
+ }
+ else if (typeDigits == 4) {
+ cout << endl;
+ setMarmaladeType(type, &blueberryMarmalades, &peachMarmalades, &rosehipMarmalades);
+ }
+ }
+
+ cout << "Мармалад от боровинки: " << blueberryMarmalades << endl;
+ cout << "Мармалад от праскови: " << peachMarmalades << endl;
+ cout << "Шипков мармалад: " << rosehipMarmalades << endl;
+}
+
+int main() {
+ ex2();
+}