题解 | #最后k个元素#
最后k个元素
https://www.nowcoder.com/practice/9e497c068b8a4f53b0f0576f89ff4ebe
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; vector<int>a; // write your code here...... cin >> n; cin >> k; int data; while(cin >> data) { a.push_back(data); n--; if(n == 0) { break; } } for(auto it = a.rbegin();it != a.rend();it++) { cout << *it << ' '; k--; if(k == 0) { break; } } return 0; }