Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
617 B
4
Indexable
Never
#include <iostream>
#include <vector>

int main() {
    int num;
    std::cin >> num;

    std::vector<int> numbers(num);
    for (int i = 0; i < num; ++i) {
        std::cin >> numbers[i];
    }

    std::vector<int> result;
    for (int i = 0; i < num; ++i) {
        if (numbers[i] % 2 == 0) {  // Even numbers
            result.push_back(numbers[i]);
        }
    }

    for (int i = 0; i < num; ++i) {
        if (numbers[i] % 2 != 0) {  // Odd numbers
            result.push_back(numbers[i]);
        }
    }

    for (int i = 0; i < num; ++i) {
        std::cout << result[i] << " ";
    }

    return 0;
}