2012年9月14日

UVa 484 - The Department of Redundancy Department


#include <cstdio>
#include <map>
using std::map;

struct link {
  int n;
  link *next;
};

int main() {
  int n, I = 0;
  map<int, int> form;
  link *head = NULL;
  link *current = NULL;
  link *prev = NULL;
  while (scanf("%d", &n) == 1) {
    form[n]++;
    if (form[n] == 1) {
      current = new link;
      current -> n = n;
      current -> next = NULL;
      if (head == NULL)
        head = current;
      else
        prev -> next = current;
      prev = current;
    }
  }

  current = head;
  while (current != NULL) {
    printf("%d %d\n", current -> n, form[current -> n]);
    current = current -> next;
  }
  return 0;
}

沒有留言:

張貼留言