Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dalnoboy75 committed Mar 9, 2024
1 parent 75ee931 commit 5e8374b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 4 additions & 2 deletions task_01/src/main.cpp
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;
}
12 changes: 6 additions & 6 deletions task_01/src/utils.cpp
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");
}
}
9 changes: 5 additions & 4 deletions task_01/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <iostream>
#include <vector>

std::pair<int,int> FindSum(int number, std::vector<int> array);
class SmallVector : public std::runtime_error{
using std::runtime_error::runtime_error;
};
class SmallVector : public std::runtime_error {
using std::runtime_error::runtime_error;
};

std::pair<int, int> FindSum(int number, std::vector<int> array);

0 comments on commit 5e8374b

Please sign in to comment.