-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AlgorithmsDafeMipt2024/add-tasks
add tasks
- Loading branch information
Showing
15 changed files
with
196 additions
and
26 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
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
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,3 +1,3 @@ | ||
# Задача на количество дней перед потеплением | ||
# Задача 1 | ||
|
||
Написать функцию в которую передается темепература за каждый день в определенный момент день, нужно вернуть количество дней до повышения температуры для каждого дня, если температура не повысится, то для этого дня поставить в результирующий массив 0. | ||
Дано целое число и массив целых чисел, нужно найти 2 числа из массива которые в сумме дадут заданное число |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME}) | ||
project(${PROJECT_NAME} C CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp") | ||
file(GLOB_RECURSE lib_source_list "../lib/src/*.cpp" "../lib/src/*.hpp") | ||
file(GLOB_RECURSE main_source_list "src/main.cpp") | ||
file(GLOB_RECURSE test_source_list "src/*.cpp") | ||
file(GLOB_RECURSE test_list "src/*test.cpp") | ||
|
||
list(REMOVE_ITEM test_source_list ${main_source_list}) | ||
list(REMOVE_ITEM source_list ${test_list}) | ||
|
||
include_directories(${PROJECT_NAME} PUBLIC src) | ||
include_directories(${PROJECT_NAME} PUBLIC ../lib/src) | ||
|
||
add_executable(${PROJECT_NAME} ${source_list}) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC Utils) | ||
|
||
# Locate GTest | ||
enable_testing() | ||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
||
# Link runTests with what we want to test and the GTest and pthread library | ||
add_executable(${PROJECT_NAME}_tests ${test_source_list}) | ||
target_link_libraries( | ||
${PROJECT_NAME}_tests | ||
GTest::gtest_main | ||
Utils | ||
) | ||
|
||
include(GoogleTest) | ||
gtest_discover_tests(${PROJECT_NAME}_tests) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Задача на стэк | ||
|
||
В данной задаче необходимо реализовать один стэк и стэк с минимумом (нельзя использовать std::stack). Получение минимума должно работать за константное время |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <iostream> | ||
|
||
int main() { 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "stack.hpp" | ||
|
||
#include <algorithm> | ||
|
||
void Stack::Push(int value) { data_.push(value); } | ||
|
||
int Stack::Pop() { | ||
auto result = data_.top(); | ||
data_.pop(); | ||
return result; | ||
} | ||
|
||
void MinStack::Push(int value) { data_.push_back(value); } | ||
|
||
int MinStack::Pop() { | ||
auto result = data_.back(); | ||
data_.pop_back(); | ||
return result; | ||
} | ||
|
||
int MinStack::GetMin() { return *std::min_element(data_.begin(), data_.end()); } |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <stack> | ||
#include <vector> | ||
|
||
class Stack { | ||
public: | ||
void Push(int value); | ||
int Pop(); | ||
|
||
private: | ||
std::stack<int> data_; | ||
}; | ||
|
||
class MinStack { | ||
public: | ||
void Push(int value); | ||
int Pop(); | ||
int GetMin(); | ||
|
||
private: | ||
std::vector<int> data_; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <stack> | ||
|
||
#include "stack.hpp" | ||
|
||
TEST(StackTest, Simple) { | ||
Stack stack; | ||
stack.Push(1); // Stack [1] | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
stack.Push(1); // Stack [1] | ||
stack.Push(2); // Stack [1, 2] | ||
ASSERT_EQ(stack.Pop(), 2); // Stack [1] | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
stack.Push(1); // Stack [1] | ||
stack.Push(2); // Stack [1, 2] | ||
ASSERT_EQ(stack.Pop(), 2); // Stack [1] | ||
stack.Push(3); // Stack [1, 3] | ||
ASSERT_EQ(stack.Pop(), 3); // Stack [1] | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
} | ||
|
||
TEST(MinStackTest, Simple) { | ||
MinStack stack; | ||
stack.Push(1); // Stack [1] | ||
ASSERT_EQ(stack.GetMin(), 1); | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
stack.Push(1); // Stack [1] | ||
stack.Push(2); // Stack [1, 2] | ||
ASSERT_EQ(stack.GetMin(), 1); | ||
ASSERT_EQ(stack.Pop(), 2); // Stack [1] | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
stack.Push(1); // Stack [1] | ||
stack.Push(2); // Stack [1, 2] | ||
ASSERT_EQ(stack.GetMin(), 1); | ||
ASSERT_EQ(stack.Pop(), 2); // Stack [1] | ||
stack.Push(3); // Stack [1, 3] | ||
ASSERT_EQ(stack.GetMin(), 1); | ||
ASSERT_EQ(stack.Pop(), 3); // Stack [1] | ||
ASSERT_EQ(stack.Pop(), 1); // Stack [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME}) | ||
project(${PROJECT_NAME} C CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp") | ||
file(GLOB_RECURSE lib_source_list "../lib/src/*.cpp" "../lib/src/*.hpp") | ||
file(GLOB_RECURSE main_source_list "src/main.cpp") | ||
file(GLOB_RECURSE test_source_list "src/*.cpp") | ||
file(GLOB_RECURSE test_list "src/*test.cpp") | ||
|
||
list(REMOVE_ITEM test_source_list ${main_source_list}) | ||
list(REMOVE_ITEM source_list ${test_list}) | ||
|
||
include_directories(${PROJECT_NAME} PUBLIC src) | ||
include_directories(${PROJECT_NAME} PUBLIC ../lib/src) | ||
|
||
add_executable(${PROJECT_NAME} ${source_list}) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC Utils) | ||
|
||
# Locate GTest | ||
enable_testing() | ||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
||
# Link runTests with what we want to test and the GTest and pthread library | ||
add_executable(${PROJECT_NAME}_tests ${test_source_list}) | ||
target_link_libraries( | ||
${PROJECT_NAME}_tests | ||
GTest::gtest_main | ||
Utils | ||
) | ||
|
||
include(GoogleTest) | ||
gtest_discover_tests(${PROJECT_NAME}_tests) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Задача на количество дней перед потеплением | ||
|
||
Написать функцию в которую передается темепература за каждый день в определенный момент день, нужно вернуть количество дней до повышения температуры для каждого дня, если температура не повысится, то для этого дня поставить в результирующий массив 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <iostream> | ||
|
||
int main() { 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "topology_sort.hpp" | ||
|
||
TEST(TopologySort, Simple) { | ||
ASSERT_EQ(1, 1); // Stack [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "topology_sort.hpp" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#pragma once |