aboutsummaryrefslogtreecommitdiff
path: root/challenge-235/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-09-20 16:15:49 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-09-20 16:15:49 +0330
commit8701808a4ca1e652ba6a38eb5914d1ca6341cbf1 (patch)
tree1e65a5733be4fad5f9793ba12a6c1624281bcf88 /challenge-235/deadmarshal/cpp/ch-1.cpp
parentaee701524950403dce06a2a835452b79eacabce1 (diff)
downloadperlweeklychallenge-club-8701808a4ca1e652ba6a38eb5914d1ca6341cbf1.tar.gz
perlweeklychallenge-club-8701808a4ca1e652ba6a38eb5914d1ca6341cbf1.tar.bz2
perlweeklychallenge-club-8701808a4ca1e652ba6a38eb5914d1ca6341cbf1.zip
TWC235
Diffstat (limited to 'challenge-235/deadmarshal/cpp/ch-1.cpp')
-rw-r--r--challenge-235/deadmarshal/cpp/ch-1.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-235/deadmarshal/cpp/ch-1.cpp b/challenge-235/deadmarshal/cpp/ch-1.cpp
new file mode 100644
index 0000000000..aeb48f9e10
--- /dev/null
+++ b/challenge-235/deadmarshal/cpp/ch-1.cpp
@@ -0,0 +1,37 @@
+#include<iostream>
+#include<vector>
+
+template<typename T>
+bool remove_one(std::vector<T> &vec)
+{
+ int c1 = 0, c2 = 0, idx1 = -1, idx2 = -1;
+ for(size_t i = 1; i < vec.size(); ++i)
+ {
+ if(vec[i] <= vec[i-1])
+ {
+ c1++;
+ idx1 = i-1;
+ }
+ }
+ for(size_t i = vec.size()-2; i > 0; --i)
+ {
+ if(vec[i] >= vec[i+1])
+ {
+ c2++;
+ idx2 = i+1;
+ }
+ }
+ if((c1 == 1) && (c2 == 1) && (idx2 - idx1 + 1 == 2)) return true;
+ if((c1 > 1) || (c2 > 1)) return false;
+ return true;
+}
+
+int main()
+{
+ std::vector<int> vec1{0,2,9,4,5},vec2{5,1,3,2},vec3{2,2,3};
+ std::cout << std::boolalpha << remove_one<int>(vec1) << '\n';
+ std::cout << std::boolalpha << remove_one<int>(vec2) << '\n';
+ std::cout << std::boolalpha << remove_one<int>(vec3) << '\n';
+ return 0;
+}
+