Website Summary Files Commits Branches @commit @diff @stats
path: root / Week11 / Exercise10.cpp
diff options
context:
space:
mode:
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Week11/Exercise10.cpp31
diff --git a/Week11/Exercise10.cpp b/Week11/Exercise10.cpp
new file mode 100644
index 0000000..4f42b06
--- /dev/null
+++ b/Week11/Exercise10.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+
+int main() {
+ const unsigned LINE_SIZE = 1024;
+
+ char line[LINE_SIZE];
+ std::cin.getline(line, LINE_SIZE);
+
+ // char е 8 битово, което означава че има 2^^8 = 256
+ // на брой различни възможни стойности.
+ // Знаем, че всяка буква всъщност е едно число, затова
+ // можем директно да го използваме като индекс.
+
+ bool encountered[256] = { 0 };
+ for (unsigned i = 0; line[i] != '\0'; i++)
+ encountered[line[i]] = true;
+
+ // Всички малки букви са отместени с 32 спрямо главните.
+ // Тоест, главна буква + 32 = съответната малка буква
+
+ bool isPangram = true;
+ for (char ch = 'A'; isPangram && ch <= 'Z'; ch++)
+ isPangram = encountered[ch] || encountered[ch + 32];
+
+ if (isPangram)
+ std::cout << "Pangram" << std::endl;
+ else
+ std::cout << "Not a pangram" << std::endl;
+
+ return 0;
+}