From e4093d32fdc9a51db4a9438dcf98c20b4611a134 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Tue, 2 May 2023 09:33:39 +0800 Subject: [PATCH] chore: big refactor --- cpp/2305/CMakeLists.txt | 4 +++- cpp/2305/{230501.cpp => LC230501.cpp} | 6 +++--- cpp/2305/{230501-CN.cpp => LC230501CN.cpp} | 4 ++-- cpp/2305/defs.h | 17 +++++++++++++++++ cpp/2305/main.cpp | 9 +++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) rename cpp/2305/{230501.cpp => LC230501.cpp} (78%) rename cpp/2305/{230501-CN.cpp => LC230501CN.cpp} (93%) create mode 100644 cpp/2305/defs.h create mode 100644 cpp/2305/main.cpp diff --git a/cpp/2305/CMakeLists.txt b/cpp/2305/CMakeLists.txt index dd1a6be..4f08a63 100644 --- a/cpp/2305/CMakeLists.txt +++ b/cpp/2305/CMakeLists.txt @@ -4,4 +4,6 @@ PROJECT(2305) SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_EXPORT_COMPILE_COMMANDS true) -ADD_EXECUTABLE(2305 230501.cpp) +FILE(GLOB src *.cpp) + +ADD_EXECUTABLE(2305 ${src}) diff --git a/cpp/2305/230501.cpp b/cpp/2305/LC230501.cpp similarity index 78% rename from cpp/2305/230501.cpp rename to cpp/2305/LC230501.cpp index 04a3dbe..81b83e3 100644 --- a/cpp/2305/230501.cpp +++ b/cpp/2305/LC230501.cpp @@ -9,12 +9,12 @@ * Return the average salary of employees excluding the minimum and maximum salary. Answers within 1e-5 of the actual answer will be accepted. */ -class Solution { +class LC230501 { public: - static inline double average(const std::vector&) noexcept; + static double average(const std::vector&) noexcept; }; -inline double Solution::average(const std::vector& salary) noexcept { +double LC230501::average(const std::vector& salary) noexcept { return ( std::reduce(salary.begin(), salary.end(), 0.0) - *std::min_element(salary.begin(), salary.end()) - diff --git a/cpp/2305/230501-CN.cpp b/cpp/2305/LC230501CN.cpp similarity index 93% rename from cpp/2305/230501-CN.cpp rename to cpp/2305/LC230501CN.cpp index e6b356a..ee1bd68 100644 --- a/cpp/2305/230501-CN.cpp +++ b/cpp/2305/LC230501CN.cpp @@ -13,13 +13,13 @@ * Return the number of minutes needed to inform all the employees about the urgent news. */ -class Solution { +class LC230501CN { public: using CVIR = const std::vector&; static int numOfMinutes(int, int, CVIR, CVIR); }; -int Solution::numOfMinutes(int n, int headID, CVIR manager, CVIR informTime) { +int LC230501CN::numOfMinutes(int n, int headID, CVIR manager, CVIR informTime) { std::vector ans(n, -1); ans[headID] = 0; std::function dp = [&](int cur) { diff --git a/cpp/2305/defs.h b/cpp/2305/defs.h new file mode 100644 index 0000000..552242c --- /dev/null +++ b/cpp/2305/defs.h @@ -0,0 +1,17 @@ +#ifndef LEETCODE_CPP_DEFS_H +#define LEETCODE_CPP_DEFS_H + +#include + +class LC230501CN { +public: + using CVIR = const std::vector&; + static int numOfMinutes(int, int, CVIR, CVIR); +}; + +class LC230501 { +public: + static double average(const std::vector&) noexcept; +}; + +#endif //LEETCODE_CPP_DEFS_H diff --git a/cpp/2305/main.cpp b/cpp/2305/main.cpp new file mode 100644 index 0000000..a18352f --- /dev/null +++ b/cpp/2305/main.cpp @@ -0,0 +1,9 @@ +#include + +#include "defs.h" + +int main() { + std::cout << LC230501::average({1, 2, 3, 4}) << std::endl; + std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl; + return 0; +}