From 439ca978bac8ffcfc6cd59bf18593302713b7fab Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 26 Jan 2021 22:00:25 +0000 Subject: Challenge 001: fix Perl and Forth, add Basic, C, C++, Lua and Python solutions --- challenge-001/paulo-custodio/cpp/ch-2.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-001/paulo-custodio/cpp/ch-2.cpp (limited to 'challenge-001/paulo-custodio/cpp/ch-2.cpp') diff --git a/challenge-001/paulo-custodio/cpp/ch-2.cpp b/challenge-001/paulo-custodio/cpp/ch-2.cpp new file mode 100644 index 0000000000..3efaf01d61 --- /dev/null +++ b/challenge-001/paulo-custodio/cpp/ch-2.cpp @@ -0,0 +1,27 @@ +/* +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 +#include + +int main(int argc, char* argv[]) { + if (argc == 2) { + int n = atoi(argv[1]); + for (int i = 1; i <= n; i++) { + if (i%15==0) + std::cout << "fizzbuzz" << std::endl; + else if (i%3==0) + std::cout << "fizz" << std::endl; + else if (i%5==0) + std::cout << "buzz" << std::endl; + else + std::cout << i << std::endl; + } + } +} -- cgit From b849218f211b83137245da638645e58f494de51b Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 26 Jan 2021 22:01:40 +0000 Subject: remove tabs --- challenge-001/paulo-custodio/cpp/ch-2.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'challenge-001/paulo-custodio/cpp/ch-2.cpp') diff --git a/challenge-001/paulo-custodio/cpp/ch-2.cpp b/challenge-001/paulo-custodio/cpp/ch-2.cpp index 3efaf01d61..a77dcba5f8 100644 --- a/challenge-001/paulo-custodio/cpp/ch-2.cpp +++ b/challenge-001/paulo-custodio/cpp/ch-2.cpp @@ -2,8 +2,8 @@ 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’ +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. */ @@ -11,17 +11,17 @@ is found in the string. #include int main(int argc, char* argv[]) { - if (argc == 2) { - int n = atoi(argv[1]); - for (int i = 1; i <= n; i++) { - if (i%15==0) - std::cout << "fizzbuzz" << std::endl; - else if (i%3==0) - std::cout << "fizz" << std::endl; - else if (i%5==0) - std::cout << "buzz" << std::endl; - else - std::cout << i << std::endl; - } - } + if (argc == 2) { + int n = atoi(argv[1]); + for (int i = 1; i <= n; i++) { + if (i%15==0) + std::cout << "fizzbuzz" << std::endl; + else if (i%3==0) + std::cout << "fizz" << std::endl; + else if (i%5==0) + std::cout << "buzz" << std::endl; + else + std::cout << i << std::endl; + } + } } -- cgit