diff options
| Commit | 3d9b1b6f61a26f506cea1959fd0dfb430259ab35 (patch) | |
|---|---|---|
| Author | 2026-01-18 15:30:07 +0200 | |
| Committer | 2026-01-18 15:30:07 +0200 | |
| Files | e36ee10f828ae481e9b156179dafdd5b370904e3 /Week14 | |
| upp-2025-solutions-main.tar upp-2025-solutions-main.tar.gz upp-2025-solutions-main.zip | ||
| Parent | 5c3b97fb2572ce8940439abd0652d2a7f7a623bd (diff) | |
6 files changed, 108 insertions, 0 deletions
| -rw-r--r-- | Week14/Exercise01.cpp | 10 | ||||
| -rw-r--r-- | Week14/Exercise02.cpp | 10 | ||||
| -rw-r--r-- | Week14/Exercise03.cpp | 16 | ||||
| -rw-r--r-- | Week14/Exercise04.cpp | 15 | ||||
| -rw-r--r-- | Week14/Exercise05.cpp | 54 | ||||
| -rw-r--r-- | Week14/README.md | 3 |
diff --git a/Week14/Exercise01.cpp b/Week14/Exercise01.cpp new file mode 100644 index 0000000..edcafe2 --- /dev/null +++ b/Week14/Exercise01.cpp @@ -0,0 +1,10 @@ +#include <iostream> + +int main() { + unsigned x; + std::cin >> x; + + std::cout << (x << 3) << std::endl; + + return 0; +} diff --git a/Week14/Exercise02.cpp b/Week14/Exercise02.cpp new file mode 100644 index 0000000..442037c --- /dev/null +++ b/Week14/Exercise02.cpp @@ -0,0 +1,10 @@ +#include <iostream> + +int main() { + unsigned x; + std::cin >> x; + + std::cout << (x * 8) << std::endl; + + return 0; +} diff --git a/Week14/Exercise03.cpp b/Week14/Exercise03.cpp new file mode 100644 index 0000000..0675116 --- /dev/null +++ b/Week14/Exercise03.cpp @@ -0,0 +1,16 @@ +#include <iostream> + +int main() { + unsigned int x; + std::cin >> x; + + unsigned bitCounter = 0; + while (x > 0) { + bitCounter ^= x; + x >>= 1; + } + + std::cout << (bitCounter & 1) << std::endl; + + return 0; +} diff --git a/Week14/Exercise04.cpp b/Week14/Exercise04.cpp new file mode 100644 index 0000000..d02ef6b --- /dev/null +++ b/Week14/Exercise04.cpp @@ -0,0 +1,15 @@ +#include <iostream> + +int main() { + unsigned int x; + std::cin >> x; + + unsigned first = (x & (0b11111111 << 24)) >> 24; + unsigned second = (x & (0b11111111 << 16)) >> 16; + unsigned third = (x & (0b11111111 << 8)) >> 8; + unsigned fourth = x & 0b11111111; + + std::cout << first << ' ' << second << ' ' << third << ' ' << fourth << std::endl; + + return 0; +} 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; +} diff --git a/Week14/README.md b/Week14/README.md new file mode 100644 index 0000000..4e3f72e --- /dev/null +++ b/Week14/README.md @@ -0,0 +1,3 @@ +# Задачи + +<https://syndamia.com/teaching/upp-2025/week14/> |
