aboutsummaryrefslogtreecommitdiff
path: root/challenge-240/paulo-custodio/cpp/ch-1.cpp
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-11-20 15:40:49 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-11-20 15:40:49 +0800
commit72dc5412e640e26601ffdebc4f0247db4c4bc7fe (patch)
treed405aa98925dfed0b745e5ec331e9498005b1de7 /challenge-240/paulo-custodio/cpp/ch-1.cpp
parent35d79358f3d12607da66ffefefed5e93c469d396 (diff)
parentfda51162ad0e1e8b4489fd2c73ef7dfdc8f0df5e (diff)
downloadperlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.gz
perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.bz2
perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-240/paulo-custodio/cpp/ch-1.cpp')
-rw-r--r--challenge-240/paulo-custodio/cpp/ch-1.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/challenge-240/paulo-custodio/cpp/ch-1.cpp b/challenge-240/paulo-custodio/cpp/ch-1.cpp
new file mode 100644
index 0000000000..723d518db2
--- /dev/null
+++ b/challenge-240/paulo-custodio/cpp/ch-1.cpp
@@ -0,0 +1,84 @@
+/*
+Challenge 240
+
+Task 1: Acronym
+Submitted by: Mohammad S Anwar
+
+You are given an array of strings and a check string.
+
+Write a script to find out if the check string is the acronym of the words in
+the given array.
+Example 1
+
+Input: @str = ("Perl", "Python", "Pascal")
+ $chk = "ppp"
+Output: true
+
+Example 2
+
+Input: @str = ("Perl", "Raku")
+ $chk = "rp"
+Output: false
+
+Example 3
+
+Input: @str = ("Oracle", "Awk", "C")
+ $chk = "oac"
+Output: true
+*/
+
+#include <algorithm>
+#include <cctype>
+#include <iostream>
+#include <string>
+#include <vector>
+using namespace std;
+
+void usage(void) {
+ cerr << "Usage: ch-1 -str s1 s2 s3 ... -chk check" << endl;
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char* argv[]) {
+ vector<string> strs;
+ string check, inits;
+
+ // parse args
+ int i = 1;
+ while (i < argc) {
+ string arg = argv[i];
+ if (arg=="-str") {
+ i++;
+ while (i < argc && argv[i][0] != '-') {
+ strs.emplace_back(argv[i]);
+ i++;
+ }
+ }
+ else if (arg=="-chk") {
+ i++;
+ if (i < argc) {
+ check = argv[i];
+ i++;
+ }
+ }
+ else {
+ usage();
+ }
+ }
+ if (strs.empty() || check.empty())
+ usage();
+
+ // process
+ transform(check.begin(), check.end(), check.begin(), ::tolower);
+
+ for (size_t i = 0; i < strs.size(); i++) {
+ inits.push_back(tolower(strs[i].front()));
+ }
+
+ if (inits==check) {
+ cout << "true" << endl;
+ }
+ else {
+ cout << "false" << endl;
+ }
+}