forked from AlgorithmsDafeMipt2024/spring_homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75ee931
commit 5e8374b
Showing
3 changed files
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,6 +1,8 @@ | ||
#include <bits/stdc++.h> | ||
#include <iostream> | ||
|
||
#include "utils.hpp" | ||
using namespace std; | ||
|
||
int main() { | ||
std::cout << "Hello World\n"; | ||
return 0; | ||
} |
This file contains 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,27 +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(""); | ||
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<int, int>{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"); | ||
} | ||
} |
This file contains 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