Website Summary Files Commits Branches @commit @diff @stats
path: root / Week06 / Exercise10.cpp
diff options
context:
space:
mode:
Commitec8ecd4dc19854007428761c330303854478201f (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-06 19:13:54 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-06 19:15:07 +0200
Files662f55a328b60a70273a5e6fc564b1511da906cf /Week06/Exercise10.cpp
upp-2025-solutions-ec8ecd4dc19854007428761c330303854478201f.tar
upp-2025-solutions-ec8ecd4dc19854007428761c330303854478201f.tar.gz
upp-2025-solutions-ec8ecd4dc19854007428761c330303854478201f.zip
Parent9242ebc4c69f2c1f550ddcc0e9235f3f409554c7 (diff)
feat(Week06): Add exercises and solutions
1 files changed, 46 insertions, 0 deletions
-rw-r--r--Week06/Exercise10.cpp46
diff --git a/Week06/Exercise10.cpp b/Week06/Exercise10.cpp
new file mode 100644
index 0000000..99049ad
--- /dev/null
+++ b/Week06/Exercise10.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+
+int main() {
+ const unsigned int SIZE = 4;
+
+ unsigned long numbers[SIZE];
+ for (int i = 0; i < SIZE; i++)
+ std::cin >> numbers[i];
+
+ unsigned long max_number = 0;
+
+ /* Това решение е ГРОЗНО!
+ * Има по-добри начини да се реализира, но тук се показва
+ * доста видно комбинаториката, т.е. как се избират индексите.
+ */
+
+ // 4 избора за първото число
+ for (int i = 0; i < SIZE; i++) {
+
+ // 3 избора за второто число
+ for (int j = 0; j < SIZE; j++) {
+ if (j == i) continue;
+
+ // 2 избора за третото число
+ for (int k = 0; k < SIZE; k++) {
+ if (k == j || k == i) continue;
+
+ // 1 избор за четвъртото число
+ for (int l = 0; l < SIZE; l++) {
+ if (l == k || l == j || l == i) continue;
+
+ unsigned long current_number = numbers[i] * 1000000000 +
+ numbers[j] * 1000000 +
+ numbers[k] * 1000 +
+ numbers[l];
+ if (current_number > max_number)
+ max_number = current_number;
+ }
+ }
+ }
+ }
+
+ std::cout << max_number << std::endl;
+
+ return 0;
+}