-
Notifications
You must be signed in to change notification settings - Fork 15
Homework 1 #8
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
Matvey-cmd
wants to merge
26
commits into
AlgorithmsDafeMipt2024:main
Choose a base branch
from
Matvey-cmd: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 #8
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fb257e5
some changes
Matvey-cmd 0aa2aa9
answers
Matvey-cmd bb99d09
change
Matvey-cmd c8700d9
Right_Test
Matvey-cmd af1274b
Right_Test_2
Matvey-cmd 7507e00
itog_changes
Matvey-cmd 978668b
some changes
Matvey-cmd 387759d
last change
Matvey-cmd 34ddb71
kast_changes
Matvey-cmd 7a93759
part of task 2
Matvey-cmd d36dde4
k_stat
Matvey-cmd 8191124
commit
Matvey-cmd f2b00ce
commit
Matvey-cmd 3e84ba7
task_3
Matvey-cmd 46fb9cf
last changes
Matvey-cmd 1e221fc
last changes
Matvey-cmd 000fc92
task02 was done
Matvey-cmd 18b4f40
tasks 1-6 are ready
Matvey-cmd ee74041
fix format
Matvey-cmd 646a630
revert task 3
Matvey-cmd 03f5e9a
revert other
Matvey-cmd c58ab3e
delete useless
Matvey-cmd 7827412
last changes
Matvey-cmd 49668c7
fix
Matvey-cmd b2361f8
fix
Matvey-cmd cc0385e
fix
Matvey-cmd 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,7 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
int main() { return 0; } | ||
#include "util.hpp" | ||
#include "utils.hpp" | ||
|
||
int main() { 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,26 @@ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "topology_sort.hpp" | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
#include "utils.hpp" | ||
|
||
TEST(TopologySort, Simple) { | ||
ASSERT_EQ(1, 1); // Stack [] | ||
TEST(utils, Simple) { | ||
ASSERT_EQ(SumOfElements(9, std::vector<int>{1, 2, 4, 5, 6, 8, 10, 12}), | ||
(std::pair<int, int>{1, 8})); | ||
ASSERT_EQ(SumOfElements(39, std::vector<int>{1, 2, 4, 5, 6, 9, 10, 35}), | ||
(std::pair<int, int>{4, 35})); | ||
ASSERT_EQ(SumOfElements(14, std::vector<int>{1, 2, 4, 5, 6, 8, 10, 12}), | ||
(std::pair<int, int>{2, 12})); | ||
EXPECT_THROW(SumOfElements(187, std::vector<int>{1, 2, 4, 6, 8, 10, 12, 15}), | ||
std::logic_error); | ||
EXPECT_THROW(SumOfElements(12, std::vector<int>{0, 1, 1, 2, 2}), | ||
std::logic_error); | ||
ASSERT_EQ( | ||
SumOfElements(1338, std::vector<int>{10, 20, 40, 50, 60, 87, 100, 1278}), | ||
(std::pair<int, int>{60, 1278})); | ||
ASSERT_EQ(SumOfElements(22, std::vector<int>{10, 10, 11, 11, 12, 15}), | ||
(std::pair<int, int>{10, 12})); | ||
EXPECT_THROW(SumOfElements(22, std::vector<int>{11}), WrongVector); | ||
EXPECT_THROW(SumOfElements(1233, std::vector<int>{}), WrongVector); | ||
} | ||
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,22 @@ | ||
#include "utils.hpp" | ||
|
||
#include <iostream> | ||
#include <utility> | ||
#include <vector> | ||
|
||
std::pair<int, int> SumOfElements(int num, const std::vector<int> arr) { | ||
if (arr.size() < 2) { | ||
throw WrongVector("Vector is too small"); | ||
} | ||
for (int i = 0, j = arr.size() - 1; i < j;) { | ||
auto sum = arr[i] + arr[j]; | ||
if (sum < num) | ||
++i; | ||
else if (sum > num) | ||
--j; | ||
else if (sum == num) { | ||
return std::pair<int, int>{arr[i], arr[j]}; | ||
} | ||
} | ||
throw std::logic_error("There is no sum of elements equal to number"); | ||
} |
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 WrongVector : public std::runtime_error { | ||
Matvey-cmd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using std::runtime_error::runtime_error; | ||
}; | ||
|
||
std::pair<int, int> SumOfElements(int num, const std::vector<int> arr); |
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.