1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include <iostream>
#include <array>
int bound(int value)
{
static std::array<int, 4> longueurpieces = {100, 1250, 1370, 1500};
auto found = std::upper_bound(longueurpieces.begin(), longueurpieces.end(), value);
if (found != longueurpieces.begin())
return *(found-1);
else
return 0;
}
int main()
{
std::cout << bound(42) << std::endl;
std::cout << bound(242) << std::endl;
std::cout << bound(1250) << std::endl;
std::cout << bound(1255) << std::endl;
std::cout << bound(9999) << std::endl;
return 0;
} |
Partager