-
Notifications
You must be signed in to change notification settings - Fork 15
Homework 1 #9
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
Open
dalnoboy75
wants to merge
9
commits into
AlgorithmsDafeMipt2024:main
Choose a base branch
from
dalnoboy75:homework_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Homework 1 #9
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a610b8f
some change
dalnoboy75 7c5dd54
task_01 completed
dalnoboy75 e893819
some changes
dalnoboy75 75ee931
fixed
dalnoboy75 5e8374b
fixed #2
dalnoboy75 ca94d91
fix
dalnoboy75 5675b0e
fix
dalnoboy75 acb80a1
fix
dalnoboy75 c892b49
fix
dalnoboy75 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { return 0; } | ||
| #include "utils.hpp" | ||
|
|
||
| int main() { | ||
| std::cout << "Hello World\n"; | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,16 @@ | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include "utils.hpp" | ||
|
|
||
| #include "topology_sort.hpp" | ||
| #include <bits/stdc++.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| TEST(TopologySort, Simple) { | ||
| ASSERT_EQ(1, 1); // Stack [] | ||
| TEST(utils, Simple) { | ||
| ASSERT_EQ(FindSum(10, std::vector<int>{2, 3, 4, 7, 12}), (std::pair<int, int>{3,7})); | ||
| ASSERT_EQ(FindSum(27,std::vector<int>{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair<int, int>{2, 25})); | ||
| ASSERT_EQ(FindSum(6, std::vector<int>{1, 5, 13, 21, 22}), (std::pair<int, int>{1, 5})); | ||
| EXPECT_THROW(FindSum(7, std::vector<int>{1, 5, 13, 21, 22}), std::logic_error); | ||
| EXPECT_THROW(FindSum(57, std::vector<int>{2, 3, 4, 7, 12}), std::logic_error); | ||
| EXPECT_THROW(FindSum(-3,std::vector<int>{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error); | ||
| EXPECT_THROW(FindSum(120,std::vector<int>{}),SmallVector); | ||
| EXPECT_THROW(FindSum(47,std::vector<int>{1}),SmallVector); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include "utils.hpp" | ||
|
|
||
| #include <iostream> | ||
| #include <stdexcept> | ||
| #include <vector> | ||
|
|
||
| std::pair<int, int> FindSum(int number, const std::vector<int> array) { | ||
| 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::make_pair(array[left_index], array[right_index]); | ||
| } | ||
| if (sum < number) { | ||
| left_index++; | ||
| } else { | ||
| right_index--; | ||
| } | ||
| } | ||
| if (array[left_index] + array[right_index] != number) { | ||
|
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. я бы убрал этот if, что-то поменяется и он не всегда работать будет, тогда функция вернет непонятно что если в этот if не зайдет |
||
| throw std::logic_error("no indexes found"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #pragma once | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| class SmallVector : public std::runtime_error { | ||
| using std::runtime_error::runtime_error; | ||
| }; | ||
|
|
||
| std::pair<int, int> FindSum(int number, std::vector<int> array); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.