// Arup Guha
// 2/14/2017
// Solution to CS1 Exam 1 Questions 1, 2

#include <stdio.h>
#include <stdlib.h>

typedef struct wine {
    char type[20];
    char brand[20];
    int rating;
} wine;

typedef struct member {
    char name[20];
    int numRated;
    wine* list;
} member;

void printList(member* club, int len);
void printWine(wine* red);

int main() {

    // Read in size of array and allocate space.
    int i, j, n;
    scanf("%d", &n);
    member* club = malloc(n*sizeof(member));

    // Go through each member.
    for (i=0; i<n; i++) {

        // Get their name and number of wines rated.
        int nWines;
        scanf("%s%d", club[i].name, &nWines);
        club[i].numRated = nWines;

        // Allocate space for the ratings.
        club[i].list = malloc(nWines*sizeof(wine));

        // Read in each rating.
        for (j=0; j<nWines; j++)
            scanf("%s%s%d", club[i].list[j].type,
                            club[i].list[j].brand, &club[i].list[j].rating);
    }

    // For testing.
    printList(club, n);

    // Free the memory.
    for (i=0; i<n; i++)
        free(club[i].list);
    free(club);

    return 0;
}

// Just for testing, prints out everything in array club (of length len).
void printList(member* club, int len) {
    int i, j;
    for (i=0; i<len; i++) {
        printf("Wine Club Member: %s\n", club[i].name);
        for (j=0; j<club[i].numRated; j++)
            printWine(&(club[i].list[j]));
    }
}

// Prints one wine rating.
void printWine(wine* red) {
    printf("%s %s %d\n", red->type, red->brand, red->rating);
}
