Skip to content

Commit

Permalink
Merge pull request #27 from Certseeds/dev
Browse files Browse the repository at this point in the history
feature: update version 0.8.2
  • Loading branch information
Certseeds authored Jun 1, 2022
2 parents 1ebae62 + e120e45 commit 7994547
Show file tree
Hide file tree
Showing 64 changed files with 2,243 additions and 38 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
- name: hardwares - cpu
run: nproc; cat /proc/cpuinfo
if: ${{matrix.os != 'windows-latest'}}

# ensure the path and files of project
- name: ensure the path and files of project
Expand All @@ -49,12 +48,10 @@ jobs:
sudo apt-get update && sudo apt-get install -y gcc-${GCC_V} g++-${GCC_V} ccache
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 111
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCC_V} 111
if: ${{matrix.os != 'windows-latest'}}
- name: prepare libopencv
run: |
sudo apt-get update && sudo apt-get install libopencv-dev
if: ${{matrix.os != 'windows-latest'}}
- name: Use cmake
run: cmake --version
Expand Down Expand Up @@ -92,7 +89,6 @@ jobs:

- name: tree
run: tree
if: ${{matrix.os != 'windows-latest'}}

- name: cache configs output
run: |
Expand All @@ -119,13 +115,11 @@ jobs:
# ensure the path and files of project
- name: ensure the path and files of project
run: sudo apt-get install tree; tree
if: ${{matrix.os != 'windows-latest'}}

- name: run script
working-directory: ./script
run: python3 file_template.py

- name: tree the packet
run: tree
if: ${{matrix.os != 'windows-latest'}}

1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/file.template.settings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16.6)

set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 8)
set(PROJECT_VERSION_PATCH 1)
set(PROJECT_VERSION_PATCH 2)
project(CS203_DSAA_template
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
DESCRIPTION "Template for Algorithm Based on C++11 and Modern CMake"
Expand Down
2 changes: 1 addition & 1 deletion algorithm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enable_testing()
set(dependencies dp fft sort tree binary_search string_search graph moderncpp)
LIST(APPEND dependencies 2021F stack array list effective_cpp)
LIST(APPEND dependencies string trie math disjoint_set divide_merge)
LIST(APPEND dependencies matrix cs302 queue)
LIST(APPEND dependencies matrix cs302 queue associative_container)
foreach (elementName IN LISTS dependencies)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${elementName})
endforeach ()
Expand Down
4 changes: 3 additions & 1 deletion algorithm/array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ list(APPEND leetcode_order 674 697 so_03 1020 717)
list(APPEND leetcode_order 724 240 so_21 so_45 so_61)
list(APPEND leetcode_order 747 766 1606 48 59)
list(APPEND leetcode_order 334 238 560 804 806)
list(APPEND leetcode_order 807 811)
list(APPEND leetcode_order 807 811 830 832 840)
list(APPEND leetcode_order 849 852 867 868 896)
list(APPEND leetcode_order 905 908 922)
LIST(TRANSFORM leetcode_order PREPEND leetcode_)

set(dependencies ${dependencies} ${leetcode_order})
Expand Down
34 changes: 34 additions & 0 deletions algorithm/array/leetcode_830.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_830_test.hpp"

namespace leetcode_830 {

vector<vector<int32_t>> leetcode_830::largeGroupPositions(const string &S) {
int end{1}, length{1};
vector<vector<int32_t>> willreturn{};
const auto s_size{static_cast<int32_t>(S.size())};
for (int32_t i{1}; i < s_size; ++i) {
end = i;
if (S[i] == S[i - 1]) {
length++;
} else {
if (length >= 3) {
willreturn.push_back({end - length, end - 1});
}
length = 1;
}
}
if (length >= 3) {
willreturn.push_back({end - length + 1, end});
}
return willreturn;
}

}
52 changes: 52 additions & 0 deletions algorithm/array/leetcode_830_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag 数组
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>

namespace leetcode_830 {
using std::vector;
using std::string;

struct leetcode_830 {
static vector<vector<int32_t>> largeGroupPositions(const string &s);
};

using Catch::Matchers::Equals;

TEST_CASE("test case 1 [test_830]", "[test_830]") {
static constexpr const char *const input{"abbxxxxzzy"};
const vector<vector<int32_t>> output{{3, 6}};
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input)));
}

TEST_CASE("test case 2 [test_830]", "[test_830]") {
static constexpr const char *const input{"abc"};
const vector<vector<int32_t>> output{};
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input)));
}

TEST_CASE("test case 3 [test_830]", "[test_830]") {
static constexpr const char *const input{"abcdddeeeeaabbbcd"};
const vector<vector<int32_t>> output{{3, 5}, {6, 9}, {12, 14}};
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input)));
}
TEST_CASE("test case 4 [test_830]", "[test_830]") {
static constexpr const char *const input{"abz"};
const vector<vector<int32_t>> output{};
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input)));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP
38 changes: 38 additions & 0 deletions algorithm/array/leetcode_832.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_832_test.hpp"

namespace leetcode_832 {

vector<vector<int>> leetcode_832::flipAndInvertImageConst(const vector<vector<int>> &image) {
const auto m{image.size()};
if (m == 0) {
return image;
}
const auto n{image.front().size()};
if (n == 0) {
return image;
}
vector<vector<int32_t>> result(image);
vector<uint8_t> traverse(n);
for (size_t i{0}; i < m; ++i) {
for (size_t left{0}, right{n - 1}; left < right && right < n; ++left, --right) {
if (image[i][left] == image[i][right]) {
result[i][left] = !image[i][left];
result[i][right] = !image[i][right];
}
}
if (n % 2 == 1) {
result[i][n / 2] = !image[i][n / 2];
}
}
return result;
}


}
56 changes: 56 additions & 0 deletions algorithm/array/leetcode_832_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag 数组
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>

namespace leetcode_832 {
using std::vector;

struct leetcode_832 {
static vector<vector<int32_t>> flipAndInvertImageConst(const vector<vector<int32_t>> &image);

};

using Catch::Matchers::Equals;

TEST_CASE("test case 1 [test_832]", "[test_832]") {
const vector<vector<int32_t>> inputs{{1, 1, 0},
{1, 0, 1},
{0, 0, 0}};
const vector<vector<int32_t>> result{
{1, 0, 0},
{0, 1, 0},
{1, 1, 1},
};
CHECK_THAT(result, Equals(leetcode_832::flipAndInvertImageConst(inputs)));
}

TEST_CASE("test case 2 [test_832]", "[test_832]") {
const vector<vector<int32_t>> inputs{{1, 1, 0, 0},
{1, 0, 0, 1},
{0, 1, 1, 1},
{1, 0, 1, 0}
};
const vector<vector<int32_t>> result{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 0, 1},
{1, 0, 1, 0}
};
CHECK_THAT(result, Equals(leetcode_832::flipAndInvertImageConst(inputs)));
}

}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP
52 changes: 52 additions & 0 deletions algorithm/array/leetcode_840.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_840_test.hpp"

namespace leetcode_840 {

bool numMagicSquaresInside_help(const vector<vector<int>> &grid, size_t x, size_t y) {
for (size_t i{0}; i < 3; ++i) {
for (size_t j{0}; j < 3; ++j) {
if (grid[x + i][y + j] > 9 || grid[x + i][y + j] < 1) {
return false;
}
}
}
return (
// 中间需要是五
grid[x + 1][y + 1] == 5 &&
grid[x][y] + grid[x + 2][y + 2] == 10 &&
grid[x + 1][y] + grid[x + 1][y + 2] == 10 &&
grid[x + 2][y] + grid[x][y + 2] == 10 &&
grid[x][y] != grid[x + 2][y + 2] &&
grid[x + 1][y] != grid[x + 1][y + 2] &&
grid[x + 2][y] != grid[x][y + 2] &&
grid[x][y] + grid[x][y + 1] + grid[x][y + 2] == 15 &&
grid[x][y] + grid[x + 1][y] + grid[x + 2][y] == 15 &&
grid[x + 2][y] + grid[x + 2][y + 1] + grid[x + 2][y + 2] == 15
);
}

int leetcode_840::numMagicSquaresInside(const vector<vector<int>> &grid) {
const auto m{grid.size()};
if (m < 3) {
return 0;
}
const auto n{grid.size()};
if (n < 3) {
return 0;
}
int count = 0;
for (size_t i{0}; i + 3 <= m; ++i) {
for (size_t j{0}; j + 3 <= n; ++j) {
count += numMagicSquaresInside_help(grid, i, j);
}
}
return count;
}
}
Loading

0 comments on commit 7994547

Please sign in to comment.