With a specific movement, cows move for three times. Guess the order of the cows before the three shuffles.
My 1st Correct Code
#include <iostream>
//scanf_s
int main() {
int N; //1~100
scanf("%d", &N);
int* a = new int[N + 1]();
int* reverse_a = new int[N + 1]();
for (int i = 1; i <= N; i++) {
scanf("%d", &a[i]);
reverse_a[a[i]] = i;
}
long* id = new long[N + 1]();
for (int i = 1; i <= N; i++) {
scanf("%ld", &id[i]);
}
long* result = new long[N + 1]();
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= N; j++) {
result[reverse_a[j]] = id[j];
}
for (int k = 1; k <= N; k++) {
id[k] = result[k];
}
}
for (int k = 1; k <= N; k++) {
printf("%ld\n", result[k]);
}
}
comments
2020-01-17
for (i = 1; i <= n; i++) scanf("%s", set[i]); for (i = 1; i <= n; i++) printf("%s\n", set[arr[arr[arr[i]]]]);
