diff --git a/task_01/first b/task_01/first new file mode 100755 index 0000000..cf7b234 Binary files /dev/null and b/task_01/first differ diff --git a/task_01/first.cpp b/task_01/first.cpp new file mode 100644 index 0000000..3c851e9 --- /dev/null +++ b/task_01/first.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +pair func(int sum, const vector &vec) +{ + int l = 0; + int r = vec.size() - 1; + while ((vec[r] + vec[l]) != sum and l < r) + { + if (vec[r] + vec[l] > sum) + r -= 1; + else + l += 1; + } + return make_pair(vec[l], vec[r]); +} + +int main() +{ + vector vec = {1, 2, 4, 5, 7}; + pair result = func(9, vec); + cout << result.first << " " << result.second; +} \ No newline at end of file diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393b..e7bf54c 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,12 @@ #include +#include +#include "util.hpp"; +using namespace std; -int main() { return 0; } + +int main() +{ + vector vec = {1, 2, 4, 5, 7}; + pair result = func(9, vec); + cout << result.first << " " << result.second; +} diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index 87cef73..15bbf0f 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,5 +1,45 @@ #include +#include +#include + + +TEST(Test1_Simple_Test, Simple) { + std::vector v = {1, 2, 3, 4, 5, 6}; + + auto result = func(7, v); + EXPECT_EQ(result.first, 1); + EXPECT_EQ(result.second, 6); +} + +TEST(Test2, Empty) { + std::vector v = {}; + + auto result = func(7, v); + EXPECT_EQ(result.first, 0); + EXPECT_EQ(result.second, 0); +} + +TEST(Test3, Small) { + std::vector v = {5}; + + auto result = func(7, v); + EXPECT_EQ(result.first, 0); + EXPECT_EQ(result.second, 0); +} + +TEST(Test4, No_Pair) { + std::vector v = {1, 3, 5, 7}; + + auto result = func(40, v); + EXPECT_EQ(result.first, -1); + EXPECT_EQ(result.second, -1); +} + +TEST(Test5, With_Negative) { + std::vector v = {-1, 3, -4, 8}; + auto result = func(-5, v); + EXPECT_EQ(result.first, -1); + EXPECT_EQ(result.second, -4); +} + -TEST(Test, Simple) { - ASSERT_EQ(1, 1); // Stack [] -} \ No newline at end of file diff --git a/task_01/src/util.hpp b/task_01/src/util.hpp new file mode 100644 index 0000000..3edea03 --- /dev/null +++ b/task_01/src/util.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +using namespace std; + +pair func(int sum, const vector &vec) +{ + if (vec.size() < 2) + return make_pair(0, 0); + int l = 0; + int r = vec.size() - 1; + while (l < r) + { + if (vec[r] + vec[l] == sum) + return make_pair(vec[l], vec[r]); + if (vec[r] + vec[l] > sum) + r -= 1; + else + l += 1; + } + return make_pair(-1, -1); +} + diff --git a/task_03/src/util.hpp b/task_03/src/util.hpp new file mode 100644 index 0000000..6655cac --- /dev/null +++ b/task_03/src/util.hpp @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; + +vector get_komb_letters(const string& num) +map button; +button[1] = {}; +button[2] = {'a', 'b', 'c'}; +button[3] = {'d', 'e', 'f'}; +button[4] = {'g', 'h', 'i'}; +button[5] = {'j', 'k', 'l'}; +button[6] = {'m', 'n', 'o'}; +button[7] = {'p', 'q', 'r', 's'}; +button[8] = {'t', 'u', 'v'}; +button[9] = {'w', 'x', 'y', 'z'}; +button[0] = {'+'} + +vector res; + +for(int i = 0; i < len(button[num[0]]); i++){ + for (int j = 0; j < len(button[num[1]]); j++){ + s = button[num[0]][i] + button[num[1]][j]; + res + + } + +} + + +