aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/paulo-custodio/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-25 23:10:01 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-26 00:07:19 +0000
commite36daeee6e93355383ad3a1c3fc43271f9a357d7 (patch)
tree094084c17e6b2ea9df64acbf7b93b18dda8346d3 /challenge-097/paulo-custodio/cpp/ch-1.cpp
parent3fa58628535d4041c7cc648c005080ca88f18c18 (diff)
downloadperlweeklychallenge-club-e36daeee6e93355383ad3a1c3fc43271f9a357d7.tar.gz
perlweeklychallenge-club-e36daeee6e93355383ad3a1c3fc43271f9a357d7.tar.bz2
perlweeklychallenge-club-e36daeee6e93355383ad3a1c3fc43271f9a357d7.zip
Add Perl, Basic, C, C++, Forth, Lua and Python solutions to challenge 097
Diffstat (limited to 'challenge-097/paulo-custodio/cpp/ch-1.cpp')
-rw-r--r--challenge-097/paulo-custodio/cpp/ch-1.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-097/paulo-custodio/cpp/ch-1.cpp b/challenge-097/paulo-custodio/cpp/ch-1.cpp
new file mode 100644
index 0000000000..cddd5df19f
--- /dev/null
+++ b/challenge-097/paulo-custodio/cpp/ch-1.cpp
@@ -0,0 +1,32 @@
+/*
+Challenge 097
+
+TASK #1
+
+*/
+
+#include <iostream>
+#include <string>
+#include <cctype>
+
+// replace in-place by ciphered text
+void caeser(int n, std::string& str) {
+ for (auto& c : str) {
+ if (isalpha(c))
+ c = ((toupper(c)-'A'+26-n)%26)+'A';
+ }
+}
+
+int main(int argc, char* argv[]) {
+ std::string str;
+ if (argc > 2) {
+ int n = atoi(argv[1]);
+ for (int i = 2; i < argc; i++) {
+ str += argv[i];
+ str += " ";
+ }
+ str.pop_back();
+ caeser(n, str);
+ std::cout << str << std::endl;
+ }
+}