2012年8月21日

UVa 119 - Greedy Gift Givers


#include <stdio.h>
#include <string.h>

typedef struct People People;

struct People {
  char name[20];
  int money;
};

int main() {
  int i, j, n, first = 0;
  while (scanf("%d\n", &n) == 1) {
    if (first)
      puts("");
    first = 1;
    People people[20];
    for (i = 0; i < n; i++) {
      scanf("%s", &people[i].name);
      people[i].money = 0;
    }
    getchar();
    for (i = 0; i < n; i++) {
      int money, Money, num;
      char name[20];
      scanf("%s %d %d", &name, &Money, &num);
      getchar();
      if (num) {
        for (j = 0; j < n; j++)
          if (!strcmp(people[j].name, name)) break;
        money = Money / num;
        people[j].money -= money * num;
      }
      while (num--) {
        scanf("%s", &name);
        for (j = 0; j < n; j++)
          if (!strcmp(people[j].name, name)) break;
        people[j].money += money;
      }
    }
    for (i = 0; i < n; i++)
      printf("%s %d\n", people[i].name, people[i].money);
  }
  return 0;
}

沒有留言:

張貼留言