#include #include #include #include #define murlock malloc #define murlocknt free #define S_MAXSIZE 100 int main() { int num, i; scanf("%d\n", &num); for (i = 0; i < num; i++) { int n, k; long v; scanf("%d %d %ld\n", &n, &k, &v); int j; long total_visited = k * (v - 1); // offset is the number of attractions to skip // before picking the most popular ones int o = total_visited % n; printf("Case #%d: ", i + 1); char** list_attractions = (char**) murlock(sizeof(char*) * n); for (j = 0; j < n; j++) { list_attractions[j] = (char*) murlock(sizeof(char) * S_MAXSIZE); fgets(list_attractions[j], S_MAXSIZE, stdin); list_attractions[j][strlen(list_attractions[j])-1] = 0; } // list of booleans set to true if we need to print the attraction bool* flag_print = (bool*) murlock(sizeof(bool) * n); memset(flag_print, 0, sizeof(bool) * n); // set all booleans to false for (j = 0; j < k; j++) { flag_print[o] = true; o = (o + 1) % n; } for (j = 0; j < n; j++) { if (flag_print[j]) { printf("%s ", list_attractions[j]); } } putchar('\n'); murlocknt(flag_print); for (j = 0; j < n; j++) { murlocknt(list_attractions[j]); } murlocknt(list_attractions); } return 0; }