aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--week09/ex1.cpp28
-rw-r--r--week09/ex2.cpp23
-rw-r--r--week09/ex3.cpp26
3 files changed, 77 insertions, 0 deletions
diff --git a/week09/ex1.cpp b/week09/ex1.cpp
new file mode 100644
index 0000000..6c57379
--- /dev/null
+++ b/week09/ex1.cpp
@@ -0,0 +1,28 @@
+#include <iostream>
+#include <cstring>
+
+int max(int a, int b) {
+ return (a > b) ? a : b;
+}
+
+int main() {
+ /* 1025 за да поберем и последната терминираща нула, ако случайно реда
+ * действително е с дължина от 1024 знака */
+ char str1[1025] = { '\0' };
+ char str2[1025] = { '\0' };
+
+ /* Последния параметър не е нужен, по подразбиране е '\n' */
+ std::cin.getline(str1, 1025);
+ std::cin.getline(str2, 1025);
+
+ int biggestSize = max(strlen(str1), strlen(str2));
+ for (int i = 0; i < biggestSize; i++) {
+ if (str1[i] != str2[i]) {
+ std::cout << '_';
+ }
+ else {
+ std::cout << str1[i];
+ }
+ }
+ std::cout << std::endl;
+}
diff --git a/week09/ex2.cpp b/week09/ex2.cpp
new file mode 100644
index 0000000..73ec11d
--- /dev/null
+++ b/week09/ex2.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+
+int main() {
+ size_t N = 0;
+ std::cin >> N;
+
+ char* str = new char[N+1];
+ std::cin.ignore();
+ std::cin.getline(str, N+1);
+
+ size_t mid = N / 2;
+ for (size_t i = mid; i < N; i++) {
+ std::cout << str[i];
+ }
+ for (size_t i = 0; i < mid; i++) {
+ std::cout << str[i];
+ }
+ std::cout << std::endl;
+ /* Как може да направим горната логика със само един цикъл?
+ * Подсказка: модулно деление */
+
+ delete[] str;
+}
diff --git a/week09/ex3.cpp b/week09/ex3.cpp
new file mode 100644
index 0000000..6baae4f
--- /dev/null
+++ b/week09/ex3.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+#include <cstring>
+
+bool isSkippable(char c) {
+ return c == ' ' || c == '.' || c == ',' || c == '!' || c == '?';
+}
+
+int main() {
+ char str[1025];
+ std::cin.getline(str, 1025);
+
+ size_t strSize = strlen(str);
+ int words = 1;
+ bool lastWasSkippable = false;
+ for (int i = 0; i < strSize; i++) {
+ if (!isSkippable(str[i]) && lastWasSkippable) {
+ words++;
+ lastWasSkippable = false;
+ }
+ else if (isSkippable(str[i])) {
+ lastWasSkippable = true;
+ }
+ }
+
+ std::cout << words << std::endl;
+}