Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitd3150b67f0b98c4c7a08e4b297d5fcb723cf609f (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-12-15 21:09:37 +0200
Committer
 GitHub <noreply@github.com>
2021-12-15 21:09:37 +0200
Filesf1b0e86562ee57e5a6e7325c8d379c93a290ed04
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.tar
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.tar.gz
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.zip
Parentba3352b47a17e81e27a565de2bc531f326c9c90d (diff)
Add files via upload
3 files changed, 162 insertions, 0 deletions
-rw-r--r--Sem. 10/example1.cpp59
-rw-r--r--Sem. 10/example2.cpp64
-rw-r--r--Sem. 10/example3.cpp39
diff --git a/Sem. 10/example1.cpp b/Sem. 10/example1.cpp
new file mode 100644
index 0000000..41a79ff
--- /dev/null
+++ b/Sem. 10/example1.cpp
@@ -0,0 +1,59 @@
+#include <iostream>
+using namespace std;
+
+bool isDigit(char ch)
+{
+ return '0' <= ch && ch <= '9';
+}
+
+void countNumbersAndDigits(const char* str, unsigned& numbersCount, unsigned& digitsCount )
+{
+ unsigned stringSize = strlen(str);
+ for (unsigned i = 0; i < stringSize; i++)
+ {
+ if (isDigit(str[i]))
+ {
+ digitsCount++;
+ if (i == 0 || !isDigit(str[i - 1]))
+ numbersCount++;
+ }
+ }
+}
+
+char* censoreNumbers(const char* str)
+{
+ unsigned digitsCount = 0;
+ unsigned numbersCount = 0;
+ countNumbersAndDigits(str, numbersCount, digitsCount);
+
+ char* result = new char[strlen(str) - digitsCount + numbersCount + 1];
+ unsigned resultIter = 0;
+
+ unsigned strIter = 0;
+
+ while (str[strIter] != '\0')
+ {
+ if (isDigit(str[strIter]))
+ {
+ if (resultIter == 0 || result[resultIter - 1] != '*')
+ result[resultIter++] = '*';
+ }
+ else
+ result[resultIter++] = str[strIter];
+ strIter++;
+ }
+ result[resultIter] = '\0';
+ return result;
+}
+
+
+int main()
+{
+ char text[] = "abdg1236gdfgfd445fdg4";
+
+ char* result = censoreNumbers(text);
+
+ cout << result << endl;
+
+ delete[] result;
+}
diff --git a/Sem. 10/example2.cpp b/Sem. 10/example2.cpp
new file mode 100644
index 0000000..5ae389c
--- /dev/null
+++ b/Sem. 10/example2.cpp
@@ -0,0 +1,64 @@
+#include <iostream>
+using namespace std;
+
+
+bool isLower(char ch)
+{
+ return 'a' <= ch && ch <= 'z';
+}
+bool isUpper(char ch)
+{
+ return 'A' <= ch && ch <= 'Z';
+}
+void countLowerAndCapitalLetters(const char* str, unsigned& lowerCount, unsigned& capitalCount)
+{
+ while (*str != '\0')
+ {
+ if (isLower(*str))
+ lowerCount++;
+ else if (isUpper(*str))
+ capitalCount++;
+
+ str++;
+ }
+}
+void getTwoStrings(const char* str, char*& lowerStr, char*& upperStr)
+{
+ unsigned lowerCount = 0;
+ unsigned upperCount = 0;
+ countLowerAndCapitalLetters(str, lowerCount, upperCount);
+
+ char* lowerSymbolsString = new char[lowerCount + 1];
+ char* upperSymbolsString = new char[upperCount + 1];
+ unsigned lowerIter = 0;
+ unsigned upperIter = 0;
+
+ while (*str != '\0')
+ {
+ if (isLower(*str))
+ lowerSymbolsString[lowerIter++] = *str;
+ else if (isUpper(*str))
+ upperSymbolsString[upperIter++] = *str;
+ str++;
+ }
+ lowerSymbolsString[lowerIter] = '\0';
+ upperSymbolsString[upperIter] = '\0';
+
+ lowerStr = lowerSymbolsString;
+ upperStr = upperSymbolsString;
+}
+
+
+int main()
+{
+ char* lowerStr = nullptr;
+ char* upperStr = nullptr;
+
+ getTwoStrings("abc34345ABCDd", lowerStr, upperStr);
+
+ cout << lowerStr << endl;
+ cout << upperStr << endl;
+
+ delete[] lowerStr, upperStr;
+
+}
diff --git a/Sem. 10/example3.cpp b/Sem. 10/example3.cpp
new file mode 100644
index 0000000..db6902b
--- /dev/null
+++ b/Sem. 10/example3.cpp
@@ -0,0 +1,39 @@
+#include <iostream>
+using namespace std;
+
+void merge(int* arr1, unsigned size1, const int* arr2, unsigned size2)
+{
+ int* result = new int[size1 + size2];
+
+ unsigned iter1 = 0;
+ unsigned iter2 = 0;
+ unsigned resultIter = 0;
+
+ while (iter1 < size1 && iter2 < size2)
+ {
+ if (arr1[iter1] <= arr2[iter2])
+ result[resultIter++] = arr1[iter1++];
+ else
+ result[resultIter++] = arr2[iter2++];
+ }
+
+ while (iter1 < size1)
+ result[resultIter++] = arr1[iter1++];
+
+ while (iter2 < size2)
+ result[resultIter++] = arr2[iter2++];
+
+ memcpy(arr1, result, sizeof(int) * (size1+ size2));
+ delete[] result;
+}
+
+int main()
+{
+
+ int arr[9] = { 1, 3, 5, 10 };
+ int arr2[] = { 2, 4, 6, 100, 9900 };
+ merge(arr, 4, arr2, 5);
+
+ for (int i = 0; i < 9; i++)
+ cout << arr[i] << " ";
+}