-
Notifications
You must be signed in to change notification settings - Fork 26
Б12-513 Кострюкова Виктория #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| #include <iostream> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| int main() { return 0; } | ||
| #include "task1.hpp" | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() { return 0; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #include "task1.hpp" | ||
|
|
||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| pair<int, int> func(const vector<int>& arr, int Summa) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. плохое название функции, непонятно что она делает( и второй параметр не по кодстайлу, параметры как и переменные с маленькой_буквы_с_подчеркиванием_если_несколько_слов, и транслит не нужно использовать, просто sum |
||
| if (arr.size() < 2) { | ||
| return {-1, -1}; | ||
| } | ||
|
|
||
| int left = 0; | ||
| int right = arr.size() - 1; | ||
|
|
||
| while (left < right) { | ||
| int sum = arr[left] + arr[right]; | ||
|
|
||
| if (sum == Summa) { | ||
| return {arr[left], arr[right]}; | ||
| } else if (sum < Summa) { | ||
| left++; | ||
| } else { | ||
| right--; | ||
| } | ||
| } | ||
|
|
||
| return {-1, -1}; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #ifndef TASK1_HPP | ||
| #define TASK1_HPP | ||
|
|
||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| std::pair<int, int> func(const std::vector<int>& arr, int S); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,72 @@ | ||
| #include <gtest/gtest.h> | ||
|
|
||
| TEST(Test, Simple) { | ||
| ASSERT_EQ(1, 1); // Stack [] | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "task1.hpp" | ||
|
|
||
| using namespace std; | ||
|
|
||
| TEST(Task1Test, SimpleTest1) { | ||
| vector<int> arr = {2, 7, 11, 15}; | ||
| int S = 9; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, 2); | ||
| EXPECT_EQ(result.second, 7); | ||
| } | ||
|
|
||
| TEST(Task1Test, SimpleTEst2) { | ||
| vector<int> arr = {1, 2, 4}; | ||
| int S = 6; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, 2); | ||
| EXPECT_EQ(result.second, 4); | ||
| } | ||
|
|
||
| TEST(Task1Test, NoSolution) { | ||
| vector<int> arr = {1, 2, 3}; | ||
| int S = 100; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, -1); | ||
| EXPECT_EQ(result.second, -1); | ||
| } | ||
|
|
||
| TEST(Task1Test, NegativeNumbers) { | ||
| vector<int> arr = {-5, -3, 0, 2, 4}; | ||
| int S = -1; | ||
| pair<int, int> result = func(arr, S); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно не исправлять, но если что-то не меняется то лучше сделать константой |
||
| EXPECT_EQ(result.first, -5); | ||
| EXPECT_EQ(result.second, 4); | ||
| } | ||
|
|
||
| TEST(Task1Test, OnlyTwo) { | ||
| vector<int> arr = {5, 10}; | ||
| int S = 15; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, 5); | ||
| EXPECT_EQ(result.second, 10); | ||
| } | ||
|
|
||
| TEST(Task1Test, OneElement) { | ||
| vector<int> arr = {5}; | ||
| int S = 5; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, -1); | ||
| EXPECT_EQ(result.second, -1); | ||
| } | ||
|
|
||
| TEST(Task1Test, EmptyArray) { | ||
| vector<int> arr; | ||
| int S = 10; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, -1); | ||
| EXPECT_EQ(result.second, -1); | ||
| } | ||
|
|
||
| TEST(Task1Test, AllNumbersSame) { | ||
| vector<int> arr = {3, 3, 3, 3}; | ||
| int S = 6; | ||
| pair<int, int> result = func(arr, S); | ||
| EXPECT_EQ(result.first, 3); | ||
| EXPECT_EQ(result.second, 3); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { return 0; } | ||
| int main() { return 0; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include "task6.hpp" | ||
|
|
||
| #include <algorithm> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int func(int N, int K, const vector<int>& arr) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут сложность O(N*K), можно просто за O(N) |
||
| long long sum = 0; | ||
| for (int i = 0; i < N; i++) { | ||
| int start = max(0, i - K + 1); | ||
| auto mini = min_element(arr.begin() + start, arr.begin() + i + 1); | ||
| sum += *mini; | ||
| } | ||
| return sum; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #ifndef TASK6_HPP | ||
| #define TASK6_HPP | ||
|
|
||
| #include <vector> | ||
|
|
||
| int func(int N, int K, const std::vector<int>& arr); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,44 @@ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| TEST(TopologySort, Simple) { | ||
| ASSERT_EQ(1, 1); // Stack [] | ||
| #include <vector> | ||
|
|
||
| #include "task6.hpp" | ||
|
|
||
| using namespace std; | ||
|
|
||
| TEST(TopologySort, Simple) { ASSERT_EQ(1, 1); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. удали) |
||
|
|
||
| TEST(Task6Test, Example1) { | ||
| vector<int> prices = {5}; | ||
| EXPECT_EQ(func(1, 1, prices), 5); | ||
| } | ||
|
|
||
| TEST(Task6Test, All_same_price) { | ||
| vector<int> prices = {4, 4, 4, 4, 4}; | ||
| EXPECT_EQ(func(5, 3, prices), 20); | ||
| } | ||
|
|
||
| TEST(Task6Test, cheap_start) { | ||
| vector<int> prices = {2, 8, 1, 5}; | ||
| EXPECT_EQ(func(4, 3, prices), 6); | ||
| } | ||
|
|
||
| TEST(Task6Test, full_storage) { | ||
| vector<int> prices = {5, 3, 4}; | ||
| EXPECT_EQ(func(3, 3, prices), 11); | ||
| } | ||
|
|
||
| TEST(Task6Test, no_storage) { | ||
| vector<int> prices = {5, 3, 4}; | ||
| EXPECT_EQ(func(3, 1, prices), 12); | ||
| } | ||
|
|
||
| TEST(Task6Test, single_day) { | ||
| vector<int> prices = {5}; | ||
| EXPECT_EQ(func(1, 1, prices), 5); | ||
| } | ||
|
|
||
| TEST(Task6Test, siding_window) { | ||
| vector<int> prices = {3, 1, 5, 2, 4}; | ||
| EXPECT_EQ(func(5, 2, prices), 9); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не приветствую использование using namespace std