Website Summary Files Commits Branches @commit @diff @stats
path: root / Week14 / Exercise05.cpp
diff options
context:
space:
mode:
Commit3d9b1b6f61a26f506cea1959fd0dfb430259ab35 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-01-18 15:30:07 +0200
Committer
 Syndamia <kamen@syndamia.com>
2026-01-18 15:30:07 +0200
Filese36ee10f828ae481e9b156179dafdd5b370904e3 /Week14/Exercise05.cpp
upp-2025-solutions-main.tar
upp-2025-solutions-main.tar.gz
upp-2025-solutions-main.zip
Parent5c3b97fb2572ce8940439abd0652d2a7f7a623bd (diff)
feat(Week14): Add solutions HEAD main
1 files changed, 54 insertions, 0 deletions
-rw-r--r--Week14/Exercise05.cpp54
diff --git a/Week14/Exercise05.cpp b/Week14/Exercise05.cpp
new file mode 100644
index 0000000..d8750b5
--- /dev/null
+++ b/Week14/Exercise05.cpp
@@ -0,0 +1,54 @@
+#include <iostream>
+
+void getSubnumbers(unsigned int x, unsigned int& first, unsigned int& second, unsigned int& third) {
+ first = (x & (0b11111111111 << 21)) >> 21;
+ second = (x & (0b11111111111 << 10)) >> 10;
+ third = x & 0b1111111111;
+}
+
+int main() {
+ unsigned int a, b;
+ std::cin >> a >> b;
+
+ unsigned int aFirst, aSecond, aThird;
+ getSubnumbers(a, aFirst, aSecond, aThird);
+
+ unsigned int bFirst, bSecond, bThird;
+ getSubnumbers(b, bFirst, bSecond, bThird);
+
+ char op;
+ std::cin >> op;
+ switch (op) {
+ case '+':
+ aFirst += bFirst;
+ aSecond += bSecond;
+ aThird += bThird;
+ break;
+
+ case '-':
+ aFirst -= bFirst;
+ aSecond -= bSecond;
+ aThird -= bThird;
+ break;
+
+ case '*':
+ aFirst *= bFirst;
+ aSecond *= bSecond;
+ aThird *= bThird;
+ break;
+
+ case '/':
+ aFirst /= bFirst;
+ aSecond /= bSecond;
+ aThird /= bThird;
+ break;
+ }
+
+ aFirst %= 0b100000000000;
+ aSecond %= 0b100000000000;
+ aThird %= 0b10000000000;
+
+ std::cout << aFirst << ' ' << aSecond << ' ' << aThird << std::endl;
+
+ return 0;
+}