#include #include #include #include #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**) malloc(sizeof(char*) * n); for (j = 0; j < n; j++) { list_attractions[j] = (char*) malloc(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*) malloc(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'); free(flag_print); for (j = 0; j < n; j++) { free(list_attractions[j]); } free(list_attractions); } return 0; }