For each case, the first line of the input file contains one integer n-length of the sequence (0 < n ≤ 10 000). The second line contains n integers numbers-a1, a2, …, an (-1 000 000 000 000 000 ≤ ai ≤ 1 000 000 000 000 000).
For each case, on the first line of the output file print the sequence in the reverse order.
5 -3 4 6 -8 9
9 -8 6 4 -3
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
stack<long long> xulie;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
while(n--){
long long b;
scanf("%lld",&b);
xulie.push(b);
}
while(!xulie.empty()){
printf("%lld ",xulie.top());
xulie.pop();
}
printf("\n") ;
}
return 0;
} #include<iostream>
using namespace std;
int main(){
int n;
while(cin>>n){
int* a=new int[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n/2;i++){
int temp=a[i];
a[i]=a[n-1-i];
a[n-1-i]=temp;
}
for(int i=0;i<n;i++){
if(i<n-1)cout<<a[i]<<" ";
else cout<<a[i];
}
cout<<endl;
}
}
#include<iostream>
using namespace std;
int main(){
int n;
while(cin>>n){
int* a=new int[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>=0;i--){
if(i>0)cout<<a[i]<<" ";
else cout<<a[i];
}
cout<<endl;
}
}
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> myStack; //定义一个栈
int main(){
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) {
int k;
scanf("%d", &k);
myStack.push(k); // 入栈
}
while (!myStack.empty()) {
printf("%d ", myStack.top()); //按顺序输出栈就行了
myStack.pop();
}
printf("\n");
}
return 0;
} #include <iostream>
#include<stack>
using namespace std;
int main() {
//这里使用栈的结构来完成数组的逆向打印
int n;
cin >> n;
stack<int>stk;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
stk.push(x);
}
for (int i = 0; i < n; i++) {
int y;
y = stk.top();
cout << y;
cout << " ";
stk.pop();
}
cout << endl;
} #include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
stack<string> str;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
str.push(s);
}
while (!str.empty()) {
cout << str.top();
str.pop();
if (!str.empty()) // 排除最后一个空格
cout << " ";
}
} #include<stdio.h>
#include<stack>
using namespace std;
int main(){
int n;
scanf("%d",&n);
stack<long long> Stack;
long long a[100000];
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
Stack.push(a[i]);
}
for(int i=0;i<n;i++){
printf("%lld ",Stack.top());
Stack.pop();
}
printf("\n");
}
//第一行输入n(0 < n ≤ 10 000). 第二行输入元素ai (-1 000 000 000 000 000 ≤ ai ≤ 1 000 000 000 000 000).
//第一行输出反序 #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
stack<int> S;
int main() {
int n, temp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
S.push(temp);
}
for (int i = 0; i < n; i++) {
cout << S.top() << " ";
S.pop();
}
return 0;
}
n = input() s = input().split() a = ' '.join(s[::-1]) print(a)