aboutsummaryrefslogtreecommitdiff
path: root/week09/ex1.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-01-05 08:17:59 +0200
committerSyndamia <kamen@syndamia.com>2024-01-05 08:17:59 +0200
commit5e2d33632ed1dfc689f14ebf1a782239411d8534 (patch)
tree3208b071ba14b549392b7aee321cdf605a0a29d5 /week09/ex1.cpp
parent6c84273107288d6c97c80117b0743dd5b8188144 (diff)
downloadupp-2023-solutions-5e2d33632ed1dfc689f14ebf1a782239411d8534.tar
upp-2023-solutions-5e2d33632ed1dfc689f14ebf1a782239411d8534.tar.gz
upp-2023-solutions-5e2d33632ed1dfc689f14ebf1a782239411d8534.zip
[w9] Added solutions for first 3 exercises
Diffstat (limited to 'week09/ex1.cpp')
-rw-r--r--week09/ex1.cpp28
1 files changed, 28 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;
+}