题解 | #Zero-complexity 逆序输出#
Zero-complexity Transposition
https://www.nowcoder.com/practice/c54775799f634c72b447ef31eb36e975
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector<long long> l;
int main() {
int counter = 0;
long long temp = 0;
while (scanf("%d",&counter) != EOF) { // 注意 while 处理多个 case
while (counter != 0)
{
scanf("%lld",&temp);
l.push_back(temp);
counter--;
}
for (int i = l.size() - 1; i >= 0; i--)
{
printf("%lld ", l[i]);
}
printf("\n");
}
return 0;
}
// 64 位输出请用 printf("%lld")
使用vector(线性表)暂存输入,再反向访问vector即可实现逆序输出。亦可使用栈或者队列