BUPT-homework/semester1/pset12/2-4-OrderedPrint.c

32 lines
603 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize("Ofast,inline")
#define MAXLEN 31
int main(void) {
int lines;
scanf("%d", &lines);
// Fancy way of allocating memory to 2d array
char *arr[lines];
for (int i = 0; i < lines; i++) {
arr[i] = malloc(sizeof(char) * MAXLEN);
}
// Populate the 2d array
for (int i = 0; i < lines; i++) {
scanf("%s", arr[i]);
}
// Populate the order array
int order[lines];
for (int i = 0; i < lines; i++) {
scanf("%d", &order[i]);
}
for (int i = 0; i < lines; i++) {
printf("%s\n", arr[order[i]]);
}
return 0;
}