Skip to content

Homework#34

Open
melanikot-mipt wants to merge 12 commits into
DafeCpp:mainfrom
melanikot-mipt:homework
Open

Homework#34
melanikot-mipt wants to merge 12 commits into
DafeCpp:mainfrom
melanikot-mipt:homework

Conversation

@melanikot-mipt
Copy link
Copy Markdown
Contributor

No description provided.

@melanikot-mipt
Copy link
Copy Markdown
Contributor Author

Готовы задания 1, 2, 4, 5, 7

Comment thread task_01/src/get_terms.hpp Outdated

using namespace std;

pair<int, int> get_terms(vector<int> v, int S) {
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.

GetTerms(const std::vector<int>& array, int sum) {...}

Comment thread task_01/src/get_terms.hpp Outdated
using namespace std;

pair<int, int> get_terms(vector<int> v, int S) {
int N = v.size();
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.

n

Comment thread task_01/src/get_terms.hpp Outdated

int l{0}, r{N - 1};

int s;
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.

cuurent_sum

Comment thread task_01/src/main.cpp Outdated
else
cout << result.first << " " << result.second << endl;
/*
python3 ./scripts/run_cases.py --tasks task_01
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.

хорошо, но я бы перенес в начало файла (что бы при открытии не крутить вниз, в поисках этой строки)

Comment thread task_02/src/get_border_index.hpp Outdated

using namespace std;

int get_border_index(vector<int> v) {
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.

то же что и в первой задаче

Comment thread task_02/src/test.cpp Outdated
ASSERT_EQ(get_border_index(v13), 0);
}

void f(int i, vector<int> v) {
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.

название по понятнее)

Comment thread task_05/src/temperature_rise.hpp
Comment thread task_05/src/topology_sort.hpp Outdated
using namespace std;

vector<int> temperature_rise(vector<int> v1) {
vector<int> stack, v2(v1.size(), 0);
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.

давай 1 строка - одно объявление

Comment thread task_07/src/merge_sort.hpp
Comment thread task_07/src/merge_sort.hpp
@melanikot-mipt
Copy link
Copy Markdown
Contributor Author

Добавлены решения и тесты к задачам 3, 10, 12. Добавлены тесты к задаче 9. Исправлены замечания.

@melanikot-mipt
Copy link
Copy Markdown
Contributor Author

Задания 8, 11, 13 добавлены

@melanikot-mipt
Copy link
Copy Markdown
Contributor Author

задание 14 тоже готово теперь

Comment thread task_02/src/get_border_index.hpp Outdated
@@ -0,0 +1,20 @@
#include <vector>

int GetBorderIndex(std::vector<int> v) {
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.

const vector&

Comment thread task_02/src/get_border_index.hpp Outdated
int GetBorderIndex(std::vector<int> v) {
int N = v.size();

if (v[1] == 1) return 0;
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.

кажется и без этих строк должно работать, если и без них работает, то зачем они?

Comment thread task_03/src/test.cpp Outdated
TEST(Test, Single) {
// Одна цифра
std::vector<std::string> empty{};
std::vector<std::string> v2{"a", "b", "c"};
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.

это можно не исправлять, но если бы тест был больше, то название переменной хорошо бы было сделать понятнее, например expected2

Comment thread task_04/src/stack.cpp Outdated
void MinStack::Push(int value) { data_.push_back(value); }
void MinStack::Push(int value) {
stack_.push_back(value);
if (min_stack_.size() == 0 || value < min_stack_.back())
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.

лучше заменить min_stack_.size() == 0 на min_stack_.empty()

Comment thread task_06/src/get_min_cost.hpp Outdated
}
min_costs.push_back(std::min(fish_cost[i], min_costs.back()));
min_sum += min_costs.back();
// std::cout << min_sum << " ";
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.

в коде не нужно оставлять закоменчиный код, если только это не часть комментария, например пример использования

и код пониже тоже удали

Comment thread task_07/src/merge_sort.hpp Outdated
@@ -0,0 +1,46 @@
#include <vector>

using namespace std;
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.

в других местах не использовали, давай и тут не будем)

Comment thread task_08/src/get_k_element.hpp Outdated

using namespace std;

int get_k_element(vector<int> v, int K, int left, int right) {
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.

GetKElement

Comment thread task_06/src/test.cpp
TEST(TopologySort, Simple) {
#include <get_min_cost.hpp>

TEST(Test, Simple) {
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.

хорошо бы добавить тестов

Comment thread task_09/src/splay_tree.cpp Outdated

#include <string>

void SplayTree::RotateLeft(Node* n) {
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.

слишком короткое имя аргумента n

Comment thread task_02/src/main.cpp
int main() { return 0; }
int main() {
int N;
std::vector<int> v;
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.

cin, cout, endl без std:: — код не скомпилируется. Нужно добавить std:: везде по аналогии с другими задачами.

Comment thread task_07/src/main.cpp
@@ -1,3 +1,20 @@
#include <iostream>
#include <merge_sort.hpp>
#include <vector>
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.

то же что и в merge_sort.hpp — в других задачах using namespace std; не используется, лучше убрать и писать std:: явно

Comment thread task_07/src/main.cpp
@@ -1,3 +1,20 @@
#include <iostream>
#include <merge_sort.hpp>
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.

лучше инклуды разделять по группам (с начала стандартные библиотеки потом другие библиотеки и в конце файлы из проекта, примерно так должно выглядеть:

#include <iostream>
#include <vector>

#include <merge_sort.hpp>

Comment thread task_11/src/main.cpp
#include <string>

int main() { return 0; }
#include "substring_search.hpp"
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.

переменная string совпадает с именем типа std::string — лучше переименовать, например в text и pattern

Comment thread task_13/src/scheduling.hpp Outdated
}
};

std::vector<Lesson> GetSelectedLessons(std::vector<Lesson>& lessons) {
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.

функция принимает вектор по неконстантной ссылке и сортирует его внутри — это неожиданно меняет данные у вызывающего кода. Лучше передавать по значению: std::vector<Lesson> GetSelectedLessons(std::vector<Lesson> lessons)

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.

тут или передавать по ссылке и ничего не возвращать, или сделать константную ссылку и работать с копией. можно конечно еще передавать rvalue ссылку (&&), но не уверен что проходили в плюсах это

@LostPointer
Copy link
Copy Markdown
Contributor

так же тесты упали

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants