BUPT-homework/semester1/pset9/6-swap.c

32 lines
454 B
C
Raw Normal View History

2021-11-25 17:04:19 +08:00
#include <stdio.h>
void swap(int *l, int *r);
int main(void) {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int tmp;
for (int i = 0; i < n; i++) {
scanf("%d", &tmp);
swap(&arr[i], &arr[tmp]);
}
for (int i = 0; i < n - 1; i++) {
printf("%d ", arr[i]);
}
printf("%d\n", arr[n - 1]);
return 0;
}
void swap(int *l, int *r) {
int temp = *l;
*l = *r;
*r = temp;
}