Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#include <iostream>

int main() { return 0; }
#include <bits/stdc++.h>
#include "utils.hpp"
using namespace std;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отделяй пустыми строками блоки кода, да и я не очень одобряю using namespace на весь файл

int main() {
vector<int> v;
int n;
cin >> n;
for(int i = 0; i < n; i++){
int a;
cin >> a;
v.push_back(a);
}
int k;
cin >> k;
cout << Func(k, v).first << " " << Func(k,v).second;
}
13 changes: 9 additions & 4 deletions task_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@

#include "utils.hpp"
#include <bits/stdc++.h>
#include <gtest/gtest.h>

#include "topology_sort.hpp"

TEST(TopologySort, Simple) {
ASSERT_EQ(1, 1); // Stack []
TEST(utils, Simple) {
ASSERT_EQ(Func(10, std::vector<int>{2, 3, 4, 7, 12}), (std::pair<int, int>{3,7}));
ASSERT_EQ(Func(27,std::vector<int>{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), (std::pair<int, int>{2, 25}));
ASSERT_EQ(Func(6, std::vector<int>{1, 5, 13, 21, 22}), (std::pair<int, int>{1, 5}));
EXPECT_THROW(Func(7, std::vector<int>{1, 5, 13, 21, 22}), std::logic_error);
EXPECT_THROW(Func(57, std::vector<int>{2, 3, 4, 7, 12}), std::logic_error);
EXPECT_THROW(Func(-3,std::vector<int>{1,2,4,5,8,10, 13,17, 20, 21, 22, 25}), std::logic_error);
}
1 change: 0 additions & 1 deletion task_01/src/topology_sort.cpp

This file was deleted.

1 change: 0 additions & 1 deletion task_01/src/topology_sort.hpp

This file was deleted.

23 changes: 23 additions & 0 deletions task_01/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "utils.hpp"
#include <iostream>
#include <stdexcept>
#include <vector>

std::pair<int, int> Func(int number, const std::vector<int> array) {
int left_ind = 0, right_ind = array.size() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай уже не экономить символы (left_index) и строки (1 объявление 1 строка)

while (left_ind < right_ind) {
int sum = array[left_ind] + array[right_ind];
if (sum == number) {
return std::pair<int, int>{array[left_ind], array[right_ind]};
}
if (sum < number) {
left_ind++;
}
else {
right_ind--;
}
}
if (array[left_ind] + array[right_ind] != number) {
throw std::logic_error("");
}
}
5 changes: 5 additions & 0 deletions task_01/src/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <iostream>
#include <vector>

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