Website Summary Files Commits Branches @commit @diff @stats
path: root / Week11 / Exercise12.cpp
diff options
context:
space:
mode:
Commit6bb7b68394ebebbc69e76bee59e9351386115453 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-12-14 21:56:30 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-12-14 21:56:30 +0200
Filesc31eb47780b5bfe4d038b6d6b8f32a385d717b96 /Week11/Exercise12.cpp
upp-2025-solutions-6bb7b68394ebebbc69e76bee59e9351386115453.tar
upp-2025-solutions-6bb7b68394ebebbc69e76bee59e9351386115453.tar.gz
upp-2025-solutions-6bb7b68394ebebbc69e76bee59e9351386115453.zip
Parent5ce214686e668bf185222b518b78d7f47a20b4fd (diff)
feat(Week11): Add solutions
1 files changed, 60 insertions, 0 deletions
-rw-r--r--Week11/Exercise12.cpp60
diff --git a/Week11/Exercise12.cpp b/Week11/Exercise12.cpp
new file mode 100644
index 0000000..3ebb947
--- /dev/null
+++ b/Week11/Exercise12.cpp
@@ -0,0 +1,60 @@
+#include <iostream>
+
+unsigned passwordGrade(const char* password) {
+ unsigned charCount = 0;
+ bool containsLetter = false, containsDigit = false, containsSpecial = false, noNeighbouring = true;
+
+ while (*password != '\0') {
+ if (('a' <= *password && *password <= 'z') ||
+ ('A' <= *password && *password <= 'Z'))
+ {
+ containsLetter = true;
+ }
+ else if ('0' <= *password && *password <= '9') {
+ containsDigit = true;
+ }
+ else {
+ containsSpecial = true;
+ }
+
+ if (password[0] == password[1]) {
+ noNeighbouring = false;
+ }
+
+ charCount++;
+ password++;
+ }
+
+ return (charCount >= 15) + containsLetter + containsDigit + containsSpecial + noNeighbouring;
+}
+
+int main() {
+ unsigned allocated = 8, size = 0;
+ char* password = new char[allocated];
+
+ char curr;
+ std::cin.get(curr);
+ while (curr != '\n') {
+ password[size++] = curr;
+ std::cin.get(curr);
+
+ // Реоразмеряване
+ if (size >= allocated) {
+ allocated *= 2;
+ char* newSentenceArray = new char[allocated];
+
+ for (unsigned i = 0; i < size; i++)
+ newSentenceArray[i] = password[i];
+
+ delete[] password;
+ password = newSentenceArray;
+ }
+ }
+ password[size] = '\0';
+
+ std::cout << passwordGrade(password) << std::endl;
+
+ delete[] password;
+
+ return 0;
+}