Anonymous user
Dinesman's multiple-dwelling problem: Difference between revisions
Dinesman's multiple-dwelling problem (view source)
Revision as of 09:14, 9 August 2020
, 3 years ago→{{header|C++}}: C++14
(→{{header|C++}}: iterate constraints with all_of) |
(→{{header|C++}}: C++14) |
||
Line 426:
=={{header|C++}}==
{{Works with|C++
<lang cpp>#include <algorithm>
#include <array>
Line 436:
int main() {
constexpr auto floors =
constexpr auto top = floors -
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;
throw "invalid tenant";
};
Line 461 ⟶ 459:
sort(tenants.begin(), tenants.end());
do {
if (all_of(constraints.begin(), constraints.end(), [](
for (const auto &t : tenants) cout << t << ' ';
cout << endl;
}
|