summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--9p40.cpp2
-rw-r--r--9p43.cpp43
-rw-r--r--9p44.cpp34
-rw-r--r--9p45.cpp12
-rw-r--r--9p46.cpp12
-rw-r--r--diff2
6 files changed, 104 insertions, 1 deletions
diff --git a/9p40.cpp b/9p40.cpp
index 517dd91..763f6f8 100644
--- a/9p40.cpp
+++ b/9p40.cpp
@@ -23,7 +23,7 @@ int main () {
while (std::cin >> word) {
svec.push_back(word);
}
-
+
svec.resize(svec.size()+svec.size()/2);
std::cout << svec.capacity() << std::endl;
return 0;
diff --git a/9p43.cpp b/9p43.cpp
new file mode 100644
index 0000000..8ba0bf3
--- /dev/null
+++ b/9p43.cpp
@@ -0,0 +1,43 @@
+#include <iostream>
+#include <string>
+
+/*
+ *
+ * 9.43
+ *
+ *
+ */
+
+std::string &replace_substr(std::string &s,
+ const std::string oldval,
+ const std::string newval) {
+
+ for(auto beg = s.begin() ; beg < s.cend() + oldval.size() + 1; ) {
+ auto oldbeg = oldval.cbegin();
+ for(auto nbeg = beg ; oldbeg != oldval.cend() ; ++oldbeg, ++nbeg) {
+ if(*oldbeg != *nbeg) {
+ break;
+ }
+ }
+
+ if(oldbeg == oldval.cend()) {
+ auto pos = beg - s.begin();
+ s.erase(pos, oldval.size());
+ s.insert(pos, newval);
+ beg = s.begin() + pos + newval.size();
+ } else {
+ ++beg;
+ }
+ }
+
+ return s;
+}
+
+int main () {
+
+ std::string a = "hahahaha WOW a WO hah WOW WOW WOW";
+ std::string b = "tho though to tho yo tho bro tho";
+ std::cout << replace_substr(a, "WOW", "wow!") << std::endl;
+ std::cout << replace_substr(b, "tho", "though") << std::endl;
+ return 0;
+}
diff --git a/9p44.cpp b/9p44.cpp
new file mode 100644
index 0000000..263d122
--- /dev/null
+++ b/9p44.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <string>
+
+/*
+ *
+ * 9.44
+ *
+ *
+ */
+
+std::string &replace_substr(std::string &s,
+ const std::string oldval,
+ const std::string newval) {
+
+ for(decltype(s.size()) i = 0 ; i < s.size() ; ) {
+ if(s.substr(i, oldval.size()) == oldval) {
+ s.replace(i, oldval.size(), newval);
+ i += newval.size();
+ } else {
+ ++i;
+ }
+ }
+
+ return s;
+}
+
+int main () {
+
+ std::string a = "hahahaha WOW a WO hah WOW WOW WOW";
+ std::string b = "tho though to tho yo tho bro tho";
+ std::cout << replace_substr(a, "WOW", "wow!") << std::endl;
+ std::cout << replace_substr(b, "tho", "though") << std::endl;
+ return 0;
+}
diff --git a/9p45.cpp b/9p45.cpp
new file mode 100644
index 0000000..58d5fbf
--- /dev/null
+++ b/9p45.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * Description
+ *
+ *
+ */
+
+int main () {
+ return 0;
+}
diff --git a/9p46.cpp b/9p46.cpp
new file mode 100644
index 0000000..58d5fbf
--- /dev/null
+++ b/9p46.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * Description
+ *
+ *
+ */
+
+int main () {
+ return 0;
+}
diff --git a/diff b/diff
new file mode 100644
index 0000000..a9d8ef4
--- /dev/null
+++ b/diff
@@ -0,0 +1,2 @@
+hahahaha wow! a WO hah wow! wow! wow!
+though thoughugh to though yo though bro though