#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main() {
int n;
int age;
stack<int> s;
queue<int> OLD;
queue<int> YOUNG;
cout << "input n";
cin >> n;
cout << "input ages";
for (int i = 0; i < n; ++i) {
cin >> age;
s.push(age);
}
while (!s.empty()) {
age = s.top();
if (age >= 20) {
OLD.push(age);
} else {
YOUNG.push(age);
}
s.pop();
}
cout << "YOUNG: ";
while (!YOUNG.empty()) {
cout << YOUNG.front() << " ";
YOUNG.pop();
}
cout << "OLD: ";
while (!OLD.empty()) {
cout << OLD.front() << " ";
OLD.pop();
}
}
Comments
Leave a comment