Website Summary Files Commits Branches @commit @diff @stats
path: root / Week11 / Exercise04.cpp
diff options
context:
space:
mode:
1 files changed, 23 insertions, 0 deletions
-rw-r--r--Week11/Exercise04.cpp23
diff --git a/Week11/Exercise04.cpp b/Week11/Exercise04.cpp
new file mode 100644
index 0000000..081973b
--- /dev/null
+++ b/Week11/Exercise04.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+
+int main() {
+ char prev = '\0', curr = prev;
+ std::cin.get(curr);
+
+ // Всеки ред се бележи с \n накрая. Ако имаме празен ред,
+ // то целия ред ще съдържа само \n.
+ // Тоест, ако имаме ред с текст, и директно след него "празен"
+ // ред, то ще имаме две \n в последователност.
+
+ unsigned count = 0;
+ while (prev != '\n' || curr != '\n') {
+ count += curr == '\n';
+
+ prev = curr;
+ std::cin.get(curr);
+ }
+
+ std::cout << count << std::endl;
+
+ return 0;
+}