Converted everything to orgmode

converted everything to orgmode and added solution to the README files
This commit is contained in:
2025-03-30 23:22:57 +02:00
parent 8719f4c140
commit 3013d7ad47
83 changed files with 1646 additions and 2510 deletions

View File

@@ -1,14 +0,0 @@
## Task
Write a program that inputs a non-negative integer `n` (but store it as `int`) and outputs the binary digits of `n` in the _correct_ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
**Hint:** In order to find the largest integer $k$ such that $2^k \leq x$, you can utilize that $k$ is the smallest integer such that $2^k > \frac{x}{2}$. This observation is particularly useful to avoid an overflow for the expression $2^k$ when searching for the most significant bit to represent $x$.
**Restrictions:**
- Libraries: only the iostream standard library header is allowed; using arrays, string or cmath is not permitted.
- Operators: you may not use bitshift operators to manipulate the numbers.
---
**Warning:** The autograder does not catch if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.

View File

@@ -0,0 +1,54 @@
#+TITLE: Task 4: From decimal to binary representation
#+AUTHOR: JirR02
* Task
Write a program that inputs a non-negative integer `n` (but store it as `int`) and outputs the binary digits of `n` in the /correct/ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
*Hint:* In order to find the largest integer \(k\) such that \(2^k \leq x\), you can utilize that \(k\) is the smallest integer such that \(2^k > \frac{x}{2}\). This observation is particularly useful to avoid an overflow for the expression \(2^k\) when searching for the most significant bit to represent \(x\).
*Restrictions:*
- Libraries: only the iostream standard library header is allowed; using arrays, string or cmath is not permitted.
- Operators: you may not use bitshift operators to manipulate the numbers.
-----
*Warning:* The autograder does not catch if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.
* Solution
#+begin_src cpp
#include <iostream>
int main() {
int i = 0; // Input integer
int d = 0; // Input Number
int a = 0; // Part of binary number
int b = 0; // Number to divide
int count = 0;
std::cin >> i;
d = i;
b = i;
if (i < 0) {
return 0;
} else if (i == 0) {
std::cout << 0;
} else {
while (d != 0) {
d = d / 2;
++count;
}
for (; count > 0; --count) {
for (int j = count; j > 1; --j) {
b = b / 2;
}
a = b % 2;
std::cout << a;
b = i;
}
}
}
#+end_src

View File

@@ -1,32 +0,0 @@
#include <iostream>
int main() {
int i = 0; // Input integer
int d = 0; // Input Number
int a = 0; // Part of binary number
int b = 0; // Number to divide
int count = 0;
std::cin >> i;
d = i;
b = i;
if (i < 0) {
return 0;
} else if (i == 0) {
std::cout << 0;
} else {
while (d != 0) {
d = d / 2;
++count;
}
for (; count > 0; --count) {
for (int j = count; j > 1; --j) {
b = b / 2;
}
a = b % 2;
std::cout << a;
b = i;
}
}
}