#include <iostream>
#include <memory>
#include <cstring>
using namespace std;
#define SIZE (10)
#define arraylen(b) (sizeof(b)/sizeof(*b))
void printArray(int array[], int offset, int len);
void reverseArray(int array[], int offset, int len);
int main() {
int array[SIZE];
int len = arraylen(array);
for (int i = 0; i < len; i++)
array[i] = i;
printArray(array, 0, len);
reverseArray(array, 0, len);
printArray(array, 0, len);
return 0;
}
void printArray(int array[], int offset, int len) {
for (int i = 0; i < len; i++)
cout << array[i + offset] << ' ';
cout << endl;
}
void reverseArray(int array[], int offset, int len) {
int *temp = new int[len];
memmove(temp, &array[offset], len * sizeof(int));
for (int i = 0; i < len; i++)
array[i + offset] = temp[len - i - 1];
delete [] temp;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIFNJWkUgKDEwKQojZGVmaW5lIGFycmF5bGVuKGIpIChzaXplb2YoYikvc2l6ZW9mKCpiKSkKCnZvaWQgcHJpbnRBcnJheShpbnQgYXJyYXlbXSwgaW50IG9mZnNldCwgaW50IGxlbik7CnZvaWQgcmV2ZXJzZUFycmF5KGludCBhcnJheVtdLCBpbnQgb2Zmc2V0LCBpbnQgbGVuKTsKCmludCBtYWluKCkgewoJCQoJaW50IGFycmF5W1NJWkVdOwoJaW50IGxlbiA9IGFycmF5bGVuKGFycmF5KTsKCQoJZm9yIChpbnQgaSA9IDA7IGkgPCBsZW47IGkrKykKCQlhcnJheVtpXSA9IGk7CgkKCXByaW50QXJyYXkoYXJyYXksIDAsIGxlbik7CglyZXZlcnNlQXJyYXkoYXJyYXksIDAsIGxlbik7CglwcmludEFycmF5KGFycmF5LCAwLCBsZW4pOwoKCXJldHVybiAwOwp9CgoKdm9pZCBwcmludEFycmF5KGludCBhcnJheVtdLCBpbnQgb2Zmc2V0LCBpbnQgbGVuKSB7Cglmb3IgKGludCBpID0gMDsgaSA8IGxlbj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