wh

 •  10个月前


include<bits/stdc++.h>

include

using namespace std; int main(){

list<int>s1;
int x;
cin>>x;
while(x!=-1){
	s1.push_back(x);
	cin>>x;
}
for(auto it=s1.rbegin();it!=s1.rend();it++){
	cout<<*it<<" ";
}
return 0;

}


评论:

我承认阁下的list很强,但如果我掏出的是stack和手搓栈,阁下又该如何应对呢

1.stack(行数确实不够极限)

#include<iostream>
#include<stack>
using namespace std;
int main()
{
	int x;
	stack<int> s;
	cin>>x;
	while(x!=-1)
	{
		s.push(x);
		cin>>x;
	}
	while(!s.empty())
	{
		cout<<s.top()<<' ';
		s.pop();
	}
	return 0;
}

2.手搓简易栈

#include<iostream>
using namespace std;
int q[10010],top,n;
int main()
{
    cin>>n;
    while(n!=-1)
    {
        q[top++]=n;
        cin>>n;
    }
    while(top!=0) cout<<q[--top]<<' ';
    return 0;
}

虚空终端  •  10个月前

请先登录,才能进行评论