From 586ed1531005b6f98e621eddd7817af311b470c2 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Mon, 1 May 2023 22:39:10 +0800 Subject: [PATCH] add: 230501 --- cpp/2305/230501.cpp | 23 +++++++++++++++++++++++ cpp/2305/CMakeLists.txt | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 cpp/2305/230501.cpp diff --git a/cpp/2305/230501.cpp b/cpp/2305/230501.cpp new file mode 100644 index 0000000..04a3dbe --- /dev/null +++ b/cpp/2305/230501.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +/** + * 1491. Average Salary Excluding the Minimum and Maximum Salary + * + * You are given an array of unique integers salary where salary[i] is the salary of the ith employee. + * 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 { +public: + static inline double average(const std::vector&) noexcept; +}; + +inline double Solution::average(const std::vector& salary) noexcept { + return ( + std::reduce(salary.begin(), salary.end(), 0.0) - + *std::min_element(salary.begin(), salary.end()) - + *std::max_element(salary.begin(), salary.end()) + ) / (salary.size() - 2); +} diff --git a/cpp/2305/CMakeLists.txt b/cpp/2305/CMakeLists.txt index 76ef743..dd1a6be 100644 --- a/cpp/2305/CMakeLists.txt +++ b/cpp/2305/CMakeLists.txt @@ -4,4 +4,4 @@ PROJECT(2305) SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_EXPORT_COMPILE_COMMANDS true) -ADD_EXECUTABLE(2305 230501-CN.cpp) +ADD_EXECUTABLE(2305 230501.cpp)