Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 10 / example1.cpp
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 /Sem. 10/example1.cpp
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
1 files changed, 59 insertions, 0 deletions
-rw-r--r--Sem. 10/example1.cpp59
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;
+}