所以我有以下三行代码困扰着我:
int choice;
std::cin >> choice;
platform = platforms[choice];
感觉它应该是一根衬板,但是我在如何实现它上受困。
我在想类似的东西:
platform = platforms[(int)operator>>(std::cin)];
但是显然不完全是因为编译器没有它。
答案 0 :(得分:0)
您需要帮助程序功能。
感谢lambda,您可以在一个表达式中做到这一点:
const highestProduct = arr => {
const sorted = arr.sort((a, b) => b - a); // Descending (from highest to lowest)
const n = [...sorted.slice(0, 3), ...sorted.slice(-2)]; // [max1, max2, max3, min1, min2]
return Math.max(n[0] * n[1] * n[2], n[0] * n[3] * n[4]); // Greater of max1 * max2 * max3 and max1 * min1 * min2
}
console.log(highestProduct([-7, 8, -3, 4, -2, -7, 7]));