自用PTA题目记录0017
以下题目序号并无实际意义
7-18 逆序存放数组中的数据,并输出指定元素
题目作者: 孙骏 单位: 武汉理工大学 代码长度限制: 16 KB 时间限制: 400 ms 内存限制: 64 MB
本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按要求输出指定的数组元素。
输入格式: 在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。第三行输入一个非负整数m(m<n)。
输出格式: 在一行中输出逆序存放后下标为m的数组元素。行末无空格。
输入样例:
6
10 8 1 2 3 4
2
输出样例:
2
代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
int len;
cin >> len;
vector<int> v(len, 0);
for (int i = 0; i < v.size(); i++)
{
cin >> v[i];
}
reverse(v.begin(), v.end());
cin >> len;
cout << v[len] << endl;
return 0;
}
总结
虽然C++苦手,不过这点程度还是勉强能写一写的
┓( ´∀` )┏
PTA提交通过截图

494



被折叠的 条评论
为什么被折叠?



