AcWing 816. 数组翻转
原题链接
简单
作者:
Crisp.
,
2024-04-16 16:44:36
,
所有人可见
,
阅读 3
简单易懂
#include<iostream>
using namespace std;
const int N = 1000;
int a[N], b[N];
void reverse(int a[], int size)
{
for (int i = size - 1; i >= 0; i--)
b[size - 1 - i] = a[i]; //把要反转的size个数逆序保存到b数组中
for (int i = 0; i < size; i++)
a[i] = b[i]; //再把b数组中保存的size个数顺序赋a数组即可
}
int main()
{
int n, size;
cin >> n >> size;
for (int i = 0; i < n; i++) cin >> a[i];
reverse(a, size);
for (int i = 0; i < n; i++) cout << a[i] << " ";
return 0;
}