A46327. 数组指定部分逆序重放将一个数组中的值按逆序重新存放。例如,原来的顺序为8,6,5,4,1。要求改为1,4,5,6,8。输入输入为两行:第一行数组中元素的个数n(n大于1,n小于100)第二行是n个整数,每两个整数之间用空格分隔。输出输出为一行:输出逆序后数组的整数,每两个整数之间用空格分隔。样例输入58 6 5 4 1样例输出1 4 5 6 8
填空题
较易
知识点
题目描述
数组指定部分逆序重放
将一个数组中的值按逆序重新存放。例如,原来的顺序为8,6,5,4,1。要求改为1,4,5,6,8。
输入
输入为两行:第一行数组中元素的个数n(n大于1,n小于100)
第二行是n个整数,每两个整数之间用空格分隔。
输出
输出为一行:输出逆序后数组的整数,每两个整数之间用空格分隔。
样例输入
5
8 6 5 4 1
样例输出
1 4 5 6 8
参考答案
#include <iostream>
#include <list>
using namespace std;
int main(){
list<int>myList;
int n,d;
cin>>n;
while(n --){
cin>>d;
myList.push_back(d);
}
myList.reverse();
for(list<int>::iterator it = myList.begin();it != myList.end();++ it){
cout<<*it<<" ";
}
cout<<endl;
return 0;
}
上一题
下一题