From a610b8f12c5f83cd01c1bc9bebb274e9688c9583 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sat, 10 Feb 2024 08:54:57 +0000 Subject: [PATCH 1/9] some change --- task_01/src/topology_sort.cpp | 1 - task_01/src/utils.cpp | 1 + task_01/src/{topology_sort.hpp => utils.hpp} | 0 3 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 task_01/src/topology_sort.cpp create mode 100644 task_01/src/utils.cpp rename task_01/src/{topology_sort.hpp => utils.hpp} (100%) diff --git a/task_01/src/topology_sort.cpp b/task_01/src/topology_sort.cpp deleted file mode 100644 index e53f670c..00000000 --- a/task_01/src/topology_sort.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "topology_sort.hpp" diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp new file mode 100644 index 00000000..0ee624c5 --- /dev/null +++ b/task_01/src/utils.cpp @@ -0,0 +1 @@ +#include "utils.hpp" diff --git a/task_01/src/topology_sort.hpp b/task_01/src/utils.hpp similarity index 100% rename from task_01/src/topology_sort.hpp rename to task_01/src/utils.hpp From 7c5dd543b6083a38d00d95421c18b072bba55e78 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:03:24 +0000 Subject: [PATCH 2/9] task_01 completed --- task_01/src/main.cpp | 19 ++++++++++++++++--- task_01/src/test.cpp | 13 +++++++++---- task_01/src/utils.cpp | 22 ++++++++++++++++++++++ task_01/src/utils.hpp | 4 ++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393ba..63f9bdbf 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,16 @@ -#include - -int main() { return 0; } +#include +#include "utils.hpp" +using namespace std; +int main() { + vector v; + int n; + cin >> n; + for(int i = 0; i < n; i++){ + int a; + cin >> a; + v.push_back(a); + } + int k; + cin >> k; + cout << Func(k, v).first << " " << Func(k,v).second; +} diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index ef5a86ae..92216c09 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,8 +1,13 @@ +#include "utils.hpp" +#include #include -#include "topology_sort.hpp" - -TEST(TopologySort, Simple) { - ASSERT_EQ(1, 1); // Stack [] +TEST(utils, Simple) { + ASSERT_EQ(Func(10, std::vector{2, 3, 4, 7, 12}), (std::pair{1,3})); + ASSERT_EQ(Func(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{1, 11})); + ASSERT_EQ(Func(6, std::vector{1, 5, 13, 21, 22}), (std::pair{0, 1})); + EXPECT_THROW(Func(7, std::vector{1, 5, 13, 21, 22}), std::logic_error); + EXPECT_THROW(Func(57, std::vector{2, 3, 4, 7, 12}), std::logic_error); + EXPECT_THROW(Func(-3,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); } diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp index 0ee624c5..05eeae50 100644 --- a/task_01/src/utils.cpp +++ b/task_01/src/utils.cpp @@ -1 +1,23 @@ #include "utils.hpp" +#include +#include +#include + +std::pair Func(int number, const std::vector array) { + int left_ind = 0, right_ind = array.size() - 1; + while (left_ind < right_ind) { + int sum = array[left_ind] + array[right_ind]; + if (sum == number) { + return std::pair{left_ind, right_ind}; + } + if (sum < number) { + left_ind++; + } + else { + right_ind--; + } + } + if (array[left_ind] + array[right_ind] != number) { + throw std::logic_error(""); + } +} \ No newline at end of file diff --git a/task_01/src/utils.hpp b/task_01/src/utils.hpp index 6f70f09b..de68d11e 100644 --- a/task_01/src/utils.hpp +++ b/task_01/src/utils.hpp @@ -1 +1,5 @@ #pragma once +#include +#include + +std::pair Func(int number, std::vector array); \ No newline at end of file From e89381931403d93b0de78bc8d346e9ef2eac850f Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:15:58 +0000 Subject: [PATCH 3/9] some changes --- task_01/src/test.cpp | 6 +++--- task_01/src/utils.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index 92216c09..debccbd0 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -4,9 +4,9 @@ #include TEST(utils, Simple) { - ASSERT_EQ(Func(10, std::vector{2, 3, 4, 7, 12}), (std::pair{1,3})); - ASSERT_EQ(Func(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{1, 11})); - ASSERT_EQ(Func(6, std::vector{1, 5, 13, 21, 22}), (std::pair{0, 1})); + ASSERT_EQ(Func(10, std::vector{2, 3, 4, 7, 12}), (std::pair{3,7})); + ASSERT_EQ(Func(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{2, 25})); + ASSERT_EQ(Func(6, std::vector{1, 5, 13, 21, 22}), (std::pair{1, 5})); EXPECT_THROW(Func(7, std::vector{1, 5, 13, 21, 22}), std::logic_error); EXPECT_THROW(Func(57, std::vector{2, 3, 4, 7, 12}), std::logic_error); EXPECT_THROW(Func(-3,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp index 05eeae50..0e3774ba 100644 --- a/task_01/src/utils.cpp +++ b/task_01/src/utils.cpp @@ -8,7 +8,7 @@ std::pair Func(int number, const std::vector array) { while (left_ind < right_ind) { int sum = array[left_ind] + array[right_ind]; if (sum == number) { - return std::pair{left_ind, right_ind}; + return std::pair{array[left_ind], array[right_ind]}; } if (sum < number) { left_ind++; From 75ee93192bee41486f676a33a1fbe5125d536319 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:25:05 +0000 Subject: [PATCH 4/9] fixed --- task_01/src/main.cpp | 12 +----------- task_01/src/test.cpp | 14 ++++++++------ task_01/src/utils.cpp | 20 ++++++++++++-------- task_01/src/utils.hpp | 5 ++++- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 63f9bdbf..8faed40e 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -2,15 +2,5 @@ #include "utils.hpp" using namespace std; int main() { - vector v; - int n; - cin >> n; - for(int i = 0; i < n; i++){ - int a; - cin >> a; - v.push_back(a); - } - int k; - cin >> k; - cout << Func(k, v).first << " " << Func(k,v).second; + return 0; } diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index debccbd0..f59781c0 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -4,10 +4,12 @@ #include TEST(utils, Simple) { - ASSERT_EQ(Func(10, std::vector{2, 3, 4, 7, 12}), (std::pair{3,7})); - ASSERT_EQ(Func(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{2, 25})); - ASSERT_EQ(Func(6, std::vector{1, 5, 13, 21, 22}), (std::pair{1, 5})); - EXPECT_THROW(Func(7, std::vector{1, 5, 13, 21, 22}), std::logic_error); - EXPECT_THROW(Func(57, std::vector{2, 3, 4, 7, 12}), std::logic_error); - EXPECT_THROW(Func(-3,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); + ASSERT_EQ(FindSum(10, std::vector{2, 3, 4, 7, 12}), (std::pair{3,7})); + ASSERT_EQ(FindSum(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{2, 25})); + ASSERT_EQ(FindSum(6, std::vector{1, 5, 13, 21, 22}), (std::pair{1, 5})); + EXPECT_THROW(FindSum(7, std::vector{1, 5, 13, 21, 22}), std::logic_error); + EXPECT_THROW(FindSum(57, std::vector{2, 3, 4, 7, 12}), std::logic_error); + EXPECT_THROW(FindSum(-3,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); + EXPECT_THROW(FindSum(120,std::vector{}),SmallVector); + EXPECT_THROW(FindSum(47,std::vector{1}),SmallVector); } diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp index 0e3774ba..7eb32607 100644 --- a/task_01/src/utils.cpp +++ b/task_01/src/utils.cpp @@ -3,21 +3,25 @@ #include #include -std::pair Func(int number, const std::vector array) { - int left_ind = 0, right_ind = array.size() - 1; - while (left_ind < right_ind) { - int sum = array[left_ind] + array[right_ind]; +std::pair FindSum(int number, const std::vector array) { + if (array.size() < 2){ + throw SmallVector(""); + } + int left_index = 0; + int right_index = array.size() - 1; + while (left_index < right_index) { + int sum = array[left_index] + array[right_index]; if (sum == number) { - return std::pair{array[left_ind], array[right_ind]}; + return std::pair{array[left_index], array[right_index]}; } if (sum < number) { - left_ind++; + left_index++; } else { - right_ind--; + right_index--; } } - if (array[left_ind] + array[right_ind] != number) { + if (array[left_index] + array[right_index] != number) { throw std::logic_error(""); } } \ No newline at end of file diff --git a/task_01/src/utils.hpp b/task_01/src/utils.hpp index de68d11e..41b7d77e 100644 --- a/task_01/src/utils.hpp +++ b/task_01/src/utils.hpp @@ -2,4 +2,7 @@ #include #include -std::pair Func(int number, std::vector array); \ No newline at end of file +std::pair FindSum(int number, std::vector array); +class SmallVector : public std::runtime_error{ + using std::runtime_error::runtime_error; +}; \ No newline at end of file From 5e8374b48365f3901ffeb738f699e547ede12182 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sat, 9 Mar 2024 06:55:02 +0000 Subject: [PATCH 5/9] fixed #2 --- task_01/src/main.cpp | 6 ++++-- task_01/src/utils.cpp | 12 ++++++------ task_01/src/utils.hpp | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 8faed40e..3919ad50 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,6 +1,8 @@ -#include +#include + #include "utils.hpp" -using namespace std; + int main() { + std::cout << "Hello World\n"; return 0; } diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp index 7eb32607..978060ed 100644 --- a/task_01/src/utils.cpp +++ b/task_01/src/utils.cpp @@ -1,27 +1,27 @@ #include "utils.hpp" + #include #include #include std::pair FindSum(int number, const std::vector array) { - if (array.size() < 2){ - throw SmallVector(""); + if (array.size() < 2) { + throw SmallVector("vector size is too small"); } int left_index = 0; int right_index = array.size() - 1; while (left_index < right_index) { int sum = array[left_index] + array[right_index]; if (sum == number) { - return std::pair{array[left_index], array[right_index]}; + return std::make_pair(array[left_index], array[right_index]); } if (sum < number) { left_index++; - } - else { + } else { right_index--; } } if (array[left_index] + array[right_index] != number) { - throw std::logic_error(""); + throw std::logic_error("no indexes found"); } } \ No newline at end of file diff --git a/task_01/src/utils.hpp b/task_01/src/utils.hpp index 41b7d77e..ebec21d9 100644 --- a/task_01/src/utils.hpp +++ b/task_01/src/utils.hpp @@ -2,7 +2,8 @@ #include #include -std::pair FindSum(int number, std::vector array); -class SmallVector : public std::runtime_error{ - using std::runtime_error::runtime_error; -}; \ No newline at end of file +class SmallVector : public std::runtime_error { + using std::runtime_error::runtime_error; +}; + +std::pair FindSum(int number, std::vector array); \ No newline at end of file From ca94d9150f14100014f9f9d22efa0717bb31fde9 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sat, 9 Mar 2024 07:01:31 +0000 Subject: [PATCH 6/9] fix --- task_01/src/test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index f59781c0..2d12eb1e 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,5 +1,6 @@ #include "utils.hpp" + #include #include From 5675b0ea40bf90b59cbc77cab83dff67537cfa88 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sun, 24 Mar 2024 10:45:37 +0000 Subject: [PATCH 7/9] fix --- task_01/src/test.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index 2d12eb1e..b0bfeb75 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,16 +1,23 @@ -#include "utils.hpp" - #include #include +#include "utils.hpp" + TEST(utils, Simple) { - ASSERT_EQ(FindSum(10, std::vector{2, 3, 4, 7, 12}), (std::pair{3,7})); - ASSERT_EQ(FindSum(27,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair{2, 25})); - ASSERT_EQ(FindSum(6, std::vector{1, 5, 13, 21, 22}), (std::pair{1, 5})); - EXPECT_THROW(FindSum(7, std::vector{1, 5, 13, 21, 22}), std::logic_error); + ASSERT_EQ(FindSum(10, std::vector{2, 3, 4, 7, 12}), + (std::pair{3, 7})); + ASSERT_EQ( + FindSum(27, std::vector{1, 2, 4, 5, 8, 10, 13, 17, 20, 21, 22, 25}), + (std::pair{2, 25})); + ASSERT_EQ(FindSum(6, std::vector{1, 5, 13, 21, 22}), + (std::pair{1, 5})); + EXPECT_THROW(FindSum(7, std::vector{1, 5, 13, 21, 22}), + std::logic_error); EXPECT_THROW(FindSum(57, std::vector{2, 3, 4, 7, 12}), std::logic_error); - EXPECT_THROW(FindSum(-3,std::vector{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); - EXPECT_THROW(FindSum(120,std::vector{}),SmallVector); - EXPECT_THROW(FindSum(47,std::vector{1}),SmallVector); + EXPECT_THROW( + FindSum(-3, std::vector{1, 2, 4, 5, 8, 10, 13, 17, 20, 21, 22, 25}), + std::logic_error); + EXPECT_THROW(FindSum(120, std::vector{}), SmallVector); + EXPECT_THROW(FindSum(47, std::vector{1}), SmallVector); } From acb80a1fcf359621bc72aa79aceff88194bfd4b2 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sat, 30 Mar 2024 12:20:00 +0000 Subject: [PATCH 8/9] fix --- task_01/src/test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index b0bfeb75..6b6b60d4 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,5 +1,3 @@ - -#include #include #include "utils.hpp" From c892b4981c6ae7cbc572172f7cc185e326d68ed9 Mon Sep 17 00:00:00 2001 From: dalnoboy75 <39648068+dalnoboy75@users.noreply.github.com> Date: Sat, 13 Apr 2024 08:44:37 +0000 Subject: [PATCH 9/9] fix --- task_01/src/utils.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/task_01/src/utils.cpp b/task_01/src/utils.cpp index 978060ed..fd5d7d2f 100644 --- a/task_01/src/utils.cpp +++ b/task_01/src/utils.cpp @@ -21,7 +21,5 @@ std::pair FindSum(int number, const std::vector array) { right_index--; } } - if (array[left_index] + array[right_index] != number) { - throw std::logic_error("no indexes found"); - } + throw std::logic_error("no indexes found"); } \ No newline at end of file