Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / task3.cpp
diff options
context:
space:
mode:
Commit91ad02e1a054521b212b2d2f4fba691c56f8d073 (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-17 21:47:36 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-17 21:47:36 +0200
Files07db3fe4286dace1723b9d220497cbc36d0b4849 /Sem. 15/task3.cpp
Introduction_to_programming_FMI-91ad02e1a054521b212b2d2f4fba691c56f8d073.tar
Introduction_to_programming_FMI-91ad02e1a054521b212b2d2f4fba691c56f8d073.tar.gz
Introduction_to_programming_FMI-91ad02e1a054521b212b2d2f4fba691c56f8d073.zip
Parent7104c90385c02473bba9880b0fcd28ffbf1940bc (diff)
Parent2d3edb414454ad28554cf73ed8fabe86f17ff337 (diff)
Merge branch 'main' of https://github.com/Angeld55/Introduction_to_programming_FMI
1 files changed, 48 insertions, 0 deletions
-rw-r--r--Sem. 15/task3.cpp48
diff --git a/Sem. 15/task3.cpp b/Sem. 15/task3.cpp
new file mode 100644
index 0000000..83bc8f3
--- /dev/null
+++ b/Sem. 15/task3.cpp
@@ -0,0 +1,48 @@
+#include <iostream>
+
+
+bool isLowerChar(char ch)
+{
+ return ch >= 'a' && ch <= 'z';
+}
+char* sortLowerChars(const char* str)
+{
+ const int ALPHABET_SIZE = 26;
+ int hist[ALPHABET_SIZE] = { 0 };
+ int newSize = 0;
+
+ while (*str != '\0')
+ {
+ if (isLowerChar(*str))
+ {
+ newSize++;
+ hist[*str - 'a']++;
+ }
+
+ str++;
+ }
+
+ char* result = new char[newSize + 1];
+ result[newSize] = '\0';
+ int resultIndex = 0;
+
+ for (int i = 0; i < ALPHABET_SIZE; i++)
+ {
+ while (hist[i] > 0)
+ {
+ result[resultIndex++] = 'a' + i;
+ hist[i]--;
+ }
+ }
+ return result;
+
+}
+
+int main()
+{
+ char* result = sortLowerChars("bbzzAaaTYb");
+
+ std::cout << result << std::endl;
+
+ delete[] result;
+} \ No newline at end of file