+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLINE 1000
+#define MAXBAGS 1000
+
+struct bag {
+ char *color;
+ struct baglist *above;
+};
+
+struct baglist {
+ struct bag *bag,
+ struct baglist *next;
+};
+
+char *bagnames[MAXBAGS];
+
+int main()
+{
+ char buffer[MAXLINE];
+
+ while (fgets(buffer, MAXLINE, stdin)) {
+ char *p;
+ p = strstr(buffer, " bag");
+ *p = 0;
+ printf("bag: %s\n", buffer);
+ p = strstr(p+1, " contain ") + strlen(" contain");
+
+ while (p) {
+ if (*p == ' ')
+ p++;
+ if (*p == 'n') {
+ printf("\tno other\n");
+ break;
+ }
+ int num = atoi(p);
+ char *bag = p = strchr(p, ' ') + 1;
+ p = strstr(p, " bag");
+ *p = 0;
+ p += strlen(" bag");
+ printf("\t%d, %s.\n", num, bag);
+ p = strchr(p, ' ');
+ }
+ }
+}