diff --git a/tourist.c b/tourist.c new file mode 100644 index 0000000..3f1cd0e --- /dev/null +++ b/tourist.c @@ -0,0 +1,59 @@ +#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; +} diff --git a/tourist.txt b/tourist.txt new file mode 100644 index 0000000..6129677 --- /dev/null +++ b/tourist.txt @@ -0,0 +1,29 @@ +6 +4 1 3 +LikeSign +Arcade +SweetStop +SwagStore +4 4 100 +FoxGazebo +MPK20Roof +WoodenSculpture +Biryani +4 3 1 +LikeSign +Arcade +SweetStop +SwagStore +4 3 3 +LikeSign +Arcade +SweetStop +SwagStore +4 3 10 +LikeSign +Arcade +SweetStop +SwagStore +2 1 1000000000000 +RainbowStairs +WallOfPhones