Skip to content

Commit

Permalink
Merge pull request #1 from AlgorithmsDafeMipt2024/add-tasks
Browse files Browse the repository at this point in the history
add tasks
  • Loading branch information
LostPointer authored Feb 3, 2024
2 parents c41d047 + 93858f7 commit 0afaec5
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 26 deletions.
30 changes: 6 additions & 24 deletions .github/workflows/clang-tidy-post.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,10 @@ jobs:
runs-on: ubuntu-latest

steps:
# Downloads the artifact uploaded by the lint action
- name: 'Download artifact'
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "clang-tidy-review"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/clang-tidy-review.zip', Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip clang-tidy-review.zip

- uses: ZedThree/clang-tidy-review/post@v0.14.0
# lgtm_comment_body, max_comments, and annotations need to be set on the posting workflow in a split setup
with:
# adjust options as necessary
lgtm_comment_body: ''
annotations: false
max_comments: 15
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
### Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты. Каждая задача отдельный ПР, полчуть дополнительные баллы можно только если пулл реквест замержен в основную ветку.

### Можно получить дополнительные баллы, если добавить теорию в папку doc. Делается в отдельном ПР, полчуть дополнительные баллы можно только если пулл реквест замержен в основную ветку.

### Код должен быть отформатирован clang-format'ом со стилем Google
4 changes: 2 additions & 2 deletions task_01/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Задача на количество дней перед потеплением
# Задача 1

Написать функцию в которую передается темепература за каждый день в определенный момент день, нужно вернуть количество дней до повышения температуры для каждого дня, если температура не повысится, то для этого дня поставить в результирующий массив 0.
Дано целое число и массив целых чисел, нужно найти 2 числа из массива которые в сумме дадут заданное число
39 changes: 39 additions & 0 deletions task_02/CMakeLists.txt
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)
3 changes: 3 additions & 0 deletions task_02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Задача на стэк

В данной задаче необходимо реализовать один стэк и стэк с минимумом (нельзя использовать std::stack). Получение минимума должно работать за константное время
3 changes: 3 additions & 0 deletions task_02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <iostream>

int main() { return 0; }
21 changes: 21 additions & 0 deletions task_02/src/stack.cpp
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()); }
23 changes: 23 additions & 0 deletions task_02/src/stack.hpp
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_;
};
42 changes: 42 additions & 0 deletions task_02/src/test.cpp
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 []
}
39 changes: 39 additions & 0 deletions task_03/CMakeLists.txt
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)
3 changes: 3 additions & 0 deletions task_03/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Задача на количество дней перед потеплением

Написать функцию в которую передается темепература за каждый день в определенный момент день, нужно вернуть количество дней до повышения температуры для каждого дня, если температура не повысится, то для этого дня поставить в результирующий массив 0.
3 changes: 3 additions & 0 deletions task_03/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <iostream>

int main() { return 0; }
8 changes: 8 additions & 0 deletions task_03/src/test.cpp
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 []
}
1 change: 1 addition & 0 deletions task_03/src/topology_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "topology_sort.hpp"
1 change: 1 addition & 0 deletions task_03/src/topology_sort.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once

0 comments on commit 0afaec5

Please sign in to comment.