aboutsummaryrefslogtreecommitdiff
path: root/week10/ex4.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-01-05 08:21:16 +0200
committerSyndamia <kamen@syndamia.com>2024-01-05 08:21:16 +0200
commitdbdce2c71e8327d5cbfa3e87840866b504efec0f (patch)
tree98730d6da3de1896f8dca5e4be5c611e13c06ba7 /week10/ex4.cpp
parent5e2d33632ed1dfc689f14ebf1a782239411d8534 (diff)
downloadupp-2023-solutions-dbdce2c71e8327d5cbfa3e87840866b504efec0f.tar
upp-2023-solutions-dbdce2c71e8327d5cbfa3e87840866b504efec0f.tar.gz
upp-2023-solutions-dbdce2c71e8327d5cbfa3e87840866b504efec0f.zip
[w10] Added solutions
Diffstat (limited to 'week10/ex4.cpp')
-rw-r--r--week10/ex4.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/week10/ex4.cpp b/week10/ex4.cpp
new file mode 100644
index 0000000..ec05144
--- /dev/null
+++ b/week10/ex4.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+
+void printNumbers(int currentBit, char* buf, const int N) {
+ if (currentBit == 0) {
+ std::cout << buf << std::endl;
+ return;
+ }
+ buf[N - currentBit] = '0';
+ printNumbers(currentBit - 1, buf, N);
+ buf[N - currentBit] = '1';
+ printNumbers(currentBit - 1, buf, N);
+}
+
+int main() {
+ int N;
+ std::cin >> N;
+
+ char* buf = new char[N+1];
+ buf[N] = '\0';
+
+ printNumbers(N, buf, N);
+ delete[] buf;
+}