题解 | #逆序输出#
逆序输出
https://www.nowcoder.com/practice/bb66c27cb7aa48f9ba7d9f88e4068285
#include <iostream> #include <vector> using namespace std; int main() { /* 解法一 int a[10] = {0}; int n = 9; while (n >= 0) { // 注意 while 处理多个 case cin >> a[n]; n--; } for(int i = 0; i < 10; i++) cout << a[i] << " "; */ // 解法二 用vector vector<int> vec; int num; while(cin >> num) { vec.push_back(num); } vector<int>::reverse_iterator rev_it; for(rev_it = vec.rbegin(); rev_it != vec.rend(); rev_it++) cout << *rev_it << " "; } // 64 位输出请用 printf("%lld")