Skip to content

Commit

Permalink
publish version v0.8.5
Browse files Browse the repository at this point in the history
publish version v0.8.5
  • Loading branch information
Certseeds committed Oct 29, 2022
2 parents 13edbdc + 50838ea commit 9d24b5b
Show file tree
Hide file tree
Showing 93 changed files with 2,950 additions and 222 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-18.04, ubuntu-latest ]
os: [ ubuntu-20.04, ubuntu-latest ]
gcc_v: [ 11 ] # Version of G++,GCC
env:
GCC_V: ${{ matrix.gcc_v }}
Expand All @@ -23,7 +23,7 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: dev
- uses: actions/cache@v3
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-18.04, ubuntu-latest ]
os: [ ubuntu-20.04, ubuntu-latest ]
gcc_v: [ 11 ] # Version of G++,GCC
env:
GCC_V: ${{ matrix.gcc_v }}
Expand All @@ -24,7 +24,7 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- uses: actions/cache@v3
env:
cache-name: cache-cmake-files
Expand Down Expand Up @@ -103,14 +103,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-18.04, ubuntu-latest ]
os: [ ubuntu-20.04, ubuntu-latest ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# ensure the path and files of project
- name: ensure the path and files of project
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-18.04, ubuntu-latest]
os: [ ubuntu-20.04, ubuntu-latest]
gcc_v: [ 11 ] # Version of G++,GCC
env:
GCC_V: ${{ matrix.gcc_v }}
Expand All @@ -25,7 +25,7 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: hardwares - cpu
run: nproc; cat /proc/cpuinfo
Expand Down Expand Up @@ -88,14 +88,14 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Branch name
id: branch_name
run: |
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: tag name output
run: |
echo ${SOURCE_NAME};echo ${SOURCE_BRANCH};echo ${SOURCE_TAG}
Expand Down Expand Up @@ -140,12 +140,12 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Branch name
id: branch_name
run: |
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: tag name output
run: |
echo ${SOURCE_NAME};
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest,ubuntu-18.04, ubuntu-latest ]
os: [ windows-latest,ubuntu-20.04, ubuntu-latest ]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Cache Packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cargo
key: ${{ matrix.os }}-rust-toolchain-${{ hashFiles('**/*.toml') }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
*.a
*.o
*.so
*.exe
4 changes: 3 additions & 1 deletion algorithm/array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ 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 941 942)
list(APPEND leetcode_order 944 977 985 986 989)
list(APPEND leetcode_order 999 1010 1013 1030)
list(APPEND leetcode_order 999 1010 1013 1030 1051)
list(APPEND leetcode_order 1089 1108 1170 1184 1200)
list(APPEND leetcode_order 1217)
LIST(TRANSFORM leetcode_order PREPEND leetcode_)

set(dependencies ${dependencies} ${leetcode_order})
Expand Down
43 changes: 43 additions & 0 deletions algorithm/array/leetcode_1051.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_1051_test.hpp"
#include <algorithm>

namespace leetcode_1051 {

int32_t leetcode_1051::heightChecker(const vector<int32_t> &heights) {
vector<int32_t> sorted{heights};
std::sort(sorted.begin(), sorted.end());
int32_t count{0};
for (size_t i{0}; i < heights.size(); ++i) {
if (sorted[i] != heights[i]) {
count++;
}
}
return count; // because the size smaller than 100
}

int leetcode_1051::heightCheckerSmall(const vector<int> &heights) {
const auto h_size{128};
vector<int32_t> sizes(128, 0);
for (const auto height: heights) {
sizes[height] += 1;
}
int32_t will_return{0};
for (int32_t j{0}, loca{0}; j < h_size; ++j) {
for (int32_t i{0}; i < sizes[j]; ++i) {
if (j != heights[loca]) {
will_return += 1;
}
loca += 1;
}
}
return will_return;
}

}
56 changes: 56 additions & 0 deletions algorithm/array/leetcode_1051_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 数组
//@Tag 排序
//@Tag 小规模数据集
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_1051_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_1051_TEST_HPP

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

namespace leetcode_1051 {
using std::vector;

struct leetcode_1051 final {
static int heightChecker(const vector<int> &heights);

static int heightCheckerSmall(const vector<int> &heights);
};


TEST_CASE("test case 1-1 {test_1051}", "{test_1051}") {
const vector<int32_t> input{1, 1, 4, 5, 1, 4};
static constexpr const auto result{4};
CHECK(result == leetcode_1051::heightChecker(input));
CHECK(result == leetcode_1051::heightCheckerSmall(input));
}

TEST_CASE("test case 1-2 {test_1051}", "{test_1051}") {
const vector<int32_t> input{5, 1, 2, 3, 4};
static constexpr const auto result{5};
CHECK(result == leetcode_1051::heightChecker(input));
CHECK(result == leetcode_1051::heightCheckerSmall(input));
}

TEST_CASE("test case 1-3 {test_1051}", "{test_1051}") {
const vector<int32_t> input{23, 52, 46, 7, 50, 87, 20, 32, 85, 65, 62, 34, 8, 86, 15, 66, 66, 30, 11, 96, 18, 26,
24, 10, 57, 13, 37, 69, 85, 6, 8, 17, 40, 88, 14, 72, 85, 51, 40, 38, 54, 65, 65, 27,
18, 59, 77, 12, 25, 46, 10, 19, 10, 28, 64, 79, 5, 88, 2, 1, 14, 50, 91, 34, 58, 32, 90,
67, 28, 81, 84, 76, 88, 45, 42, 54, 59, 56, 20, 6, 56, 51, 72, 69, 6, 48, 67, 68, 6, 10,
93, 69, 4, 29, 28};
static constexpr const auto result{95};
CHECK(result == leetcode_1051::heightChecker(input));
CHECK(result == leetcode_1051::heightCheckerSmall(input));
}

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

namespace leetcode_1089 {

void leetcode_1089::duplicateZeros(vector<int> &arr) {
const auto arr_size{arr.size()};
size_t left_pointer{0}, right_pointer{0};
for (; left_pointer < arr_size && right_pointer < arr_size; left_pointer += 1, right_pointer += 1) {
if (arr[left_pointer] == 0) {
right_pointer += 1;
}
}// 先进行一次模拟step by step,之后反演
// 不能只从左向右扫描0的个数,可能前面的会把后面的给"顶"出去
for (; left_pointer > 0 && right_pointer > 0; left_pointer -= 1, right_pointer -= 1) {
const auto left_number{arr[left_pointer - 1]};
if (left_number != 0) {
arr[right_pointer - 1] = arr[left_pointer - 1];
} else {
right_pointer -= 1;
if (right_pointer < arr_size) [[unlikely]] { // max once
arr[right_pointer] = 0;
}
arr[right_pointer - 1] = 0;
}
}
}

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

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

namespace leetcode_1089 {
using std::vector;

struct leetcode_1089 final {
static void duplicateZeros(vector<int> &arr);

static vector<int32_t> duplicateZerosConst(const vector<int32_t> &arr) {
vector<int32_t> will_return{arr};
duplicateZeros(will_return);
return will_return;
}
};

using Catch::Matchers::Equals;

TEST_CASE("test case 1-1 {test_1089}", "{test_1089}") {
const vector<int32_t> input{1, 1, 4, 5, 1, 4};
const vector<int32_t> result{1, 1, 4, 5, 1, 4};
CHECK_THAT(result, Equals(leetcode_1089::duplicateZerosConst(input)));
}

TEST_CASE("test case 1-2 {test_1089}", "{test_1089}") {
const vector<int32_t> input{1, 0, 2, 0, 3, 4, 0};
const vector<int32_t> result{1, 0, 0, 2, 0, 0, 3};
CHECK_THAT(result, Equals(leetcode_1089::duplicateZerosConst(input)));
}

TEST_CASE("test case 1-3 {test_1089}", "{test_1089}") {
const vector<int32_t> input{1, 9, 1, 9, 8, 1, 0};
const vector<int32_t> result{1, 9, 1, 9, 8, 1, 0};
CHECK_THAT(result, Equals(leetcode_1089::duplicateZerosConst(input)));
}

TEST_CASE("test case 1-4 {test_1089}", "{test_1089}") {
const vector<int32_t> input{8, 5, 0, 9, 0, 3, 4, 7};
const vector<int32_t> result{8, 5, 0, 0, 9, 0, 0, 3};
CHECK_THAT(result, Equals(leetcode_1089::duplicateZerosConst(input)));
}

TEST_CASE("test case 1-5 {test_1089}", "{test_1089}") {
const vector<int32_t> input{0, 1, 7, 6, 0, 2, 0,7};
const vector<int32_t> result{0, 0, 1, 7, 6, 0, 0, 2};
CHECK_THAT(result, Equals(leetcode_1089::duplicateZerosConst(input)));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_1089_TEST_HPP
42 changes: 42 additions & 0 deletions algorithm/array/leetcode_1108.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_1108_test.hpp"

namespace leetcode_1108 {

string leetcode_1108::defangIPaddr(const string &address) {
const int8_t add_size{static_cast<int8_t>(address.size())};
string will_return(add_size + 6, ' ');
std::array<int8_t, 5> position{-1, 0, 0, 0, add_size};
// .255.100.50.0.
for (int8_t i{0}, cnt{1}; i < add_size; ++i) {
if (address[i] == '.') {
position[cnt] = i;
cnt++;
}
}
auto iter = will_return.begin();
for (size_t i{0}; i < 3; ++i) {
for (int8_t j = position[i] + static_cast<int8_t>(1); j < position[i + 1]; ++j) {
(*iter) = address[j];
++iter;
}
(*iter) = '[';
++iter;
(*iter) = '.';
++iter;
(*iter) = ']';
++iter;
}
for (int8_t j = position[3] + static_cast<int8_t>(1); j < position[4]; ++j) {
(*iter) = address[j];
++iter;
}
return will_return;
}
}
Loading

0 comments on commit 9d24b5b

Please sign in to comment.