include iostream include stack int main std stack int stack1 stack2 fo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <stack>
int main(){
std::stack<int> stack1, stack2;
for ( int i = -50; i < 51; ++i )
stack1.push(i);
int cnt = 0;
while ( ! stack1.empty() ) {
if ( ++cnt % 3 == 0 )
stack2.push(stack1.top());
stack1.pop();
}
while ( ! stack2.empty() ) {
std::cout << stack2.top() << " ";
stack2.pop();
}
std::cout << std::endl;
return 0;
}