Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Exams / Exam2 / prob1.cpp
diff options
context:
space:
mode:
Commit3d7b742eb8e9012e21a0516ad21fc7aefd043bf7 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-01-11 10:09:44 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-01-11 10:09:44 +0200
Filesda790d25fcfa3251a8f57ee531c6a4fddd64804e /Year 1/Programming introduction/Exams/Exam2/prob1.cpp
uni-projects-3d7b742eb8e9012e21a0516ad21fc7aefd043bf7.tar
uni-projects-3d7b742eb8e9012e21a0516ad21fc7aefd043bf7.tar.gz
uni-projects-3d7b742eb8e9012e21a0516ad21fc7aefd043bf7.zip
Parenta6fd917db5d633aecfe0307b016108e78dd2f4f7 (diff)
Added my work from todays up exam
1 files changed, 34 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Exams/Exam2/prob1.cpp34
diff --git a/Year 1/Programming introduction/Exams/Exam2/prob1.cpp b/Year 1/Programming introduction/Exams/Exam2/prob1.cpp
new file mode 100644
index 0000000..76d3971
--- /dev/null
+++ b/Year 1/Programming introduction/Exams/Exam2/prob1.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+
+bool isAlphanumeric(char ch) {
+ return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
+}
+
+char* minWord(char *str) {
+ int startIndex = 0;
+ while (str[startIndex] != '\0' && !isAlphanumeric(str[startIndex]))
+ startIndex++;
+
+ char *ptr = &str[startIndex];
+
+ for (int i = startIndex, wordStart = 0; str[i] != '\0'; i++) {
+ for (int j = i; isAlphanumeric(str[i]) && isAlphanumeric(ptr[wordStart]); i++, wordStart++) {
+ if (str[i] < ptr[wordStart])
+ ptr = &str[j];
+ else if (str[i] != ptr[wordStart])
+ break;
+ }
+ wordStart = 0;
+ }
+
+ return ptr;
+}
+
+int main() {
+ char input[] = "me? why always me?";
+ char *str = minWord(input);
+
+ for (int i = 0; str[i] != '\0'; i++)
+ std::cout << str[i];
+ std::cout << std::endl;
+}