Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#include <iostream>
#include <vector>

int main() { return 0; }
// proverka 2

int main() {
int a;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

не очень хорошие названия переменных

int x;
std::cin >> a;
std::vector<int> b;
while (std::cin >> x) {
b.push_back(x);
}

int i = 0;
int j = b.size() - 1;
while (b[i] + b[j] != a) {
if (b[i] + b[j] < a) i++;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++i

if (b[i] + b[j] > a) j--;
}
std::cout << b[i] << ' ' << b[j] << '\n';
return 0;
}
15 changes: 10 additions & 5 deletions task_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@

#include <gtest/gtest.h>

#include "topology_sort.hpp"
#include <vector>

#include "utils.hpp"

TEST(main, Simple) {
ASSERT_EQ(Task1(9, std::vector<int>{1, 2, 4, 5, 6, 8, 10, 12}),
(std::pair<int, int>{1, 8}));

TEST(TopologySort, Simple) {
ASSERT_EQ(1, 1); // Stack []
}
ASSERT_EQ(Task1(39, std::vector<int>{1, 2, 4, 5, 6, 9, 10, 35}),
(std::pair<int, int>{4, 35}));
}
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.

11 changes: 11 additions & 0 deletions task_01/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "utils.hpp"

std::pair<int, int> Task1(int m, std::vector<int> a) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

давай назовем переменные как-то по другому, а не просто a, m

int i = 0;
int j = a.size() - 1;
while (a[i] + a[j] != m) {
if (a[i] + a[j] < m) i++;
if (a[i] + a[j] > m) j--;
}
return {a[i], a[j]};
}
4 changes: 4 additions & 0 deletions task_01/src/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <iostream>
#include <vector>

std::pair<int, int> Task1(int n, std::vector<int> a);