#include #include #include std::vector makeNecklace(const std::vector& beads) { std::vector blue, red; // Separate even (blue) and odd (red) numbers for (int num : beads) { if (num % 2 == 0) blue.push_back(num); else red.push_back(num); } // Sort both groups in ascending order std::sort(blue.begin(), blue.end()); std::sort(red.begin(), red.end()); // Construct the necklace: red numbers first, then blue numbers in reverse order std::vector necklace; necklace.insert(necklace.end(), red.begin(), red.end()); // Append red (left side) necklace.insert(necklace.end(), blue.rbegin(), blue.rend()); // Append blue (right side) return necklace; } int main() { // Input 10 numbers std::vector beads = {15, 16, 48, 45, 32, 37, 77, 72, 80, 85}; // Get the arranged necklace std::vector necklace = makeNecklace(beads); // Output the necklace for (int num : necklace) { std::cout << num << " "; } std::cout << std::endl; return 0; }