summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-10-12 15:06:05 +0200
committerOskar <[email protected]>2024-10-12 15:06:05 +0200
commit428d857359b5d8b639ca41b03ca8fc8b3d143a50 (patch)
tree6c6291c2404386673ef6cd65ad435374e519d35b
parentf46aaa42631113d83bc211a9db4f85ef68afdc92 (diff)
more
-rw-r--r--9p18.cpp25
-rw-r--r--9p19.cpp25
-rw-r--r--9p20.cpp37
-rw-r--r--9p21.cpp27
-rw-r--r--9p22.cpp23
5 files changed, 137 insertions, 0 deletions
diff --git a/9p18.cpp b/9p18.cpp
new file mode 100644
index 0000000..e7df6fa
--- /dev/null
+++ b/9p18.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+#include <deque>
+
+/*
+ *
+ * 9.18
+ *
+ *
+ */
+
+int main () {
+
+ std::string input;
+ std::deque<std::string> ds;
+ while(std::cin >> input) {
+ ds.push_back(input);
+ }
+
+ for(auto cbeg = ds.cbegin() ; cbeg != ds.cend() ; ++cbeg) {
+ std::cout << *cbeg << " ";
+ }
+
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/9p19.cpp b/9p19.cpp
new file mode 100644
index 0000000..6c47476
--- /dev/null
+++ b/9p19.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+#include <list>
+
+/*
+ *
+ * 9.19
+ *
+ * Changes needed: Include list, Change deque in to list.
+ */
+
+int main () {
+
+ std::string input;
+ std::list<std::string> ds;
+ while(std::cin >> input) {
+ ds.push_back(input);
+ }
+
+ for(auto cbeg = ds.cbegin() ; cbeg != ds.cend() ; ++cbeg) {
+ std::cout << *cbeg << " ";
+ }
+
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/9p20.cpp b/9p20.cpp
new file mode 100644
index 0000000..84cb78b
--- /dev/null
+++ b/9p20.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <list>
+#include <deque>
+
+/*
+ *
+ * 9.20
+ *
+ *
+ */
+
+int main () {
+
+ std::deque<int> odd;
+ std::deque<int> even;
+ std::list<int> numbers = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
+ for(auto &a : numbers) {
+ if((a % 2) == 0) {
+ even.push_back(a);
+ } else {
+ odd.push_back(a);
+ }
+ }
+
+ std::cout << "Even: \n";
+ for(auto &a : even) {
+ std::cout << a << " ";
+ }
+
+ std::cout << "\nOdd: \n";
+ for(auto &a : odd) {
+ std::cout << a << " ";
+ }
+
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/9p21.cpp b/9p21.cpp
new file mode 100644
index 0000000..be101b9
--- /dev/null
+++ b/9p21.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+#include <list>
+#include <vector>
+
+/*
+ *
+ * 9.21
+ *
+ * It's the same thing. Vector does not have push_front so this would be necessary.
+ * It's an expensive operation to do this so it woul be best to use a deque
+ */
+
+int main () {
+
+ std::string word;
+ std::vector<std::string> lst;
+ auto iter = lst.begin();
+ while (std::cin >> word) {
+ iter = lst.insert(iter, word); // same as calling push_front
+ }
+
+ for(auto &a : lst) {
+ std::cout << a << std::endl;
+ }
+
+ return 0;
+}
diff --git a/9p22.cpp b/9p22.cpp
new file mode 100644
index 0000000..90a7f92
--- /dev/null
+++ b/9p22.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <vector>
+
+/*
+ *
+ * 9.22
+ *
+ * I don't know what the author intends for the program to do.
+ * It may be obvious to the author but if he does tell me then
+ * it could be anything.
+ */
+
+int main () {
+
+ int some_val = 0;
+ std::vector<int> iv = {1,2,3,4,5,6,7,8};
+ std::vector<int>::iterator iter = iv.begin(),
+ mid = iv.begin() + iv.size()/2;
+ while (iter != mid)
+ if (*iter == some_val)
+ iv.insert(iter, 2 * some_val);
+ return 0;
+}