Problem B Done. Added test input

This commit is contained in:
Claudio Maggioni 2019-03-21 21:33:38 +01:00
parent 9d7dbd6d16
commit c35f37467f
2 changed files with 88 additions and 0 deletions

59
tourist.c Normal file
View file

@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#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;
}

29
tourist.txt Normal file
View file

@ -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