题解 | 神秘石像的镜像序列
神秘石像的镜像序列
https://www.nowcoder.com/practice/fa34eea974234610b6d3d81790cb2949?tpId=383&tqId=11211421&channelPut=tracker1
#include <iostream>//由于要逆序输出,我们可以考虑用栈,因为stack是先进后出的容器
#include <stack>//stack的头文件
using namespace std;
using ll = long long ;
int main()
{
int x;
stack<ll>p;//创造一个空栈
while(cin>>x){
if(x!=0){//题目说了不包括数字0,所以用个if语句判断一下
p.push(x);
}
}
while(!p.empty()){
ll t = p.top();//访问栈顶,即最先入栈的数
cout<<t<<" ";
p.pop();//删除栈顶元素,
}
return 0;
}

