C++ 数组翻转:前 size 个元素反转
#include
const int N = 1010;
int n, size; int a[N];
void reverse(int a[], int size) { for (int i = 0, j = size - 1; i < j; i ++, j -- ) swap(a[i], a[j]); }
int main() { 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;
}
原文地址: https://www.cveoy.top/t/topic/oDtx 著作权归作者所有。请勿转载和采集!