1 solutions
-
0
1.栈的特性:后进先出
#include<bits/stdc++.h> using namespace std; stack<int> stk; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); while(1) { int x;cin>>x; if(x==0)break; else stk.push(x); } while(!stk.empty()) { cout<<stk.top()<<' '; stk.pop(); } return 0; }
2.vector
#include<bits/stdc++.h> using namespace std; vector<int> v; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); while(1) { int x;cin>>x; if(x==0)break; else v.push_back(x); } reverse(v.begin(),v.end()); for(auto &i:v)cout<<i<<' '; return 0; }
- 1
Information
- ID
- 3852
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 2
- Accepted
- 1
- Uploaded By