首页 > 试题广场 >

#includeusing&nb...

[单选题]
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<int>st;
int pos = 1;
while(pos <= 3){
st.push(pos++);
}
cout<<st.top();
while(pos <= 5){
st.push(pos++);
}
while(!st.empty()){
cout<<st.top();
st.pop();
}
return 0;
}
上述程序的输出为(      )
  • 35421
  • 354321
  • 12453
  • 123453
此题,pos开始等于1,然后循环入栈1,2,3入站,并输出栈顶元素,此时pos等于3,再一次入栈,注意此时并没有进行出栈操作,循环入栈4,5,也就是说此时栈中元素为1,2,3,4,5。循环出栈为54321,所以答案是354321。
发表于 2019-10-09 12:05:06 回复(0)
为什么 不是 35421 啊!
发表于 2019-08-27 10:35:09 回复(2)