aboutsummaryrefslogtreecommitdiff
path: root/challenge-001/paulo-custodio/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-001/paulo-custodio/cpp/ch-1.cpp')
-rw-r--r--challenge-001/paulo-custodio/cpp/ch-1.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-001/paulo-custodio/cpp/ch-1.cpp b/challenge-001/paulo-custodio/cpp/ch-1.cpp
new file mode 100644
index 0000000000..057288b514
--- /dev/null
+++ b/challenge-001/paulo-custodio/cpp/ch-1.cpp
@@ -0,0 +1,34 @@
+/*
+Challenge 001
+
+Challenge #1
+Write a script to replace the character ‘e’ with ‘E’ in the string
+‘Perl Weekly Challenge’. Also print the number of times the character ‘e’
+is found in the string.
+*/
+
+#include <iostream>
+#include <string>
+
+int replace_e(std::string& text) {
+ int count = 0;
+ for (auto& c : text) {
+ if (c == 'e') {
+ c = 'E';
+ count++;
+ }
+ }
+ return count;
+}
+
+int main(int argc, char* argv[]) {
+ std::string text;
+ for (int i = 1; i < argc; i++) {
+ text += argv[i];
+ text += " ";
+ }
+ if (!text.empty())
+ text.pop_back(); // remove last space
+
+ std::cout << replace_e(text) << " " << text << std::endl;
+}