Dinesman's multiple-dwelling problem: Difference between revisions

(→‎{{header|C++}}: iterate constraints with all_of)
Line 426:
 
=={{header|C++}}==
{{Works with|C++1114}}
<lang cpp>#include <algorithm>
#include <array>
Line 436:
 
int main() {
constexpr auto floors = 55u;
constexpr auto top = floors - 11u, bottom = 0u;
constexpr auto bottom = 0;
 
using namespace std;
Line 444 ⟶ 443:
const auto floor_of = [&tenants](string t) {
for (int i = bottom; i <= top; i++)
if (tenants[i] == t) return i;
return i;
throw "invalid tenant";
};
Line 461 ⟶ 459:
sort(tenants.begin(), tenants.end());
do {
if (all_of(constraints.begin(), constraints.end(), [](function<bool()>auto f) { return f(); } )) {
for (const auto &t : tenants) cout << t << ' ';
cout << t << ' ';
cout << endl;
}
Anonymous user