本来是在链表里的比赛,可是我没用链表,主要是链表不会排序......
最后输出奖项的时候卡了好长时间,最后还是问的芳姐 · - ·
本来是150ms的,去掉几个没用的排序之后,成10ms了,还是跑秒了=_=!
/**************************************
Problem id : SDUT OJ J
User name : Silence—Debug
Result : Accepted
Take Memory : 1328K
Take Time : 10MS
Submit Time : 2013-03-20 20:28:08
**************************************/
# include <stdio.h> # include <string.h> # include <stdlib.h> struct node { char s[1000]; int score; int p; } a[1000]; int cmp(const void *x, const void *y) { return ((struct node *)y) -> score - ((struct node *)x) -> score; } int main(void) { int i, t, n, j, prize, f; char ch, str[100]; scanf("%d", &n); for(i = 0; i < n; i++) scanf("%s %d", a[i].s, &a[i].score); while(~scanf("%c", &ch)) { if(ch == 'O') break; else if(ch == 'S') { qsort(a, n, sizeof(struct node), cmp); for(i = 0; i < n; i++) { if(a[i].score != 0) printf("%s %d\n", a[i].s, a[i].score); } } else if(ch == 'A') { scanf("%s%d", str, &t); strcpy(a[n].s, str); a[n].score = t; n++; } else if(ch == 'Q') { scanf("%s", str); getchar(); for(i = 0; i < n; i++) if(strcmp(a[i].s, str) == 0) a[i].score = 0; } else if(ch == 'C') { scanf("%s%d", str, &t); for(i = 0; i < n; i++) if(strcmp(a[i].s, str) == 0) a[i].score += t; } } qsort(a, n, sizeof(struct node), cmp); prize = 2; f = 1; j = 0; printf("#1 :"); for(i = 0; i < n; i++) { if(a[i].score == a[j].score) printf(" %s", a[i].s); else { f++; j = i; if(f == 2 || f == 4) { puts(""); printf("#%d :", prize++); } if(f == 7) break; printf(" %s", a[i].s); } } return 0; }