add: 230501

This commit is contained in:
Eatswap 2023-05-01 22:39:10 +08:00
parent c3e72eb840
commit 586ed15310
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 24 additions and 1 deletions

23
cpp/2305/230501.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <algorithm>
#include <numeric>
#include <vector>
/**
* 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<int>&) noexcept;
};
inline double Solution::average(const std::vector<int>& 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);
}

View File

@ -4,4 +4,4 @@ PROJECT(2305)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
SET(CMAKE_EXPORT_COMPILE_COMMANDS true) SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
ADD_EXECUTABLE(2305 230501-CN.cpp) ADD_EXECUTABLE(2305 230501.cpp)