#include #include #include int func(const void *a, const void *b){ return *(int *)b - *(int *)a; } typedef struct{ int point; char name[21]; }TAG; typedef struct{ int id; int tag_cnt; char tag_name[100][21]; int point; }picture; int main(){ int N, i, j, k, l = 0; int tag_p[100] = {0}; char tag[100][21] = {'\0'}; int cnt = 0, flag = 0, flag3 = 0, pre_flag3 = 0; picture pic[100], *p; TAG a[100], b[100], tmp, *p1; int flag2[100] = {0}; scanf("%d\n", &N); for(i = 0; i < N; i++){ p = &pic[i]; scanf("%d %d %d ", &p->id, &p->tag_cnt, &p->point); for(j = 0; j < p->tag_cnt; j++){ scanf("%s ", p->tag_name[j]); } if(i == 0){ for(j = 0; j < p->tag_cnt; j++){ strcpy(tag[j], p->tag_name[j]); tag_p[j] += p->point; cnt++; } }else{ for(j = 0; j < p->tag_cnt; j++){ for(k = 0; k < cnt; k++){ if(strcmp(p->tag_name[j], tag[k]) != 0){ flag++; }else{ tag_p[k] += p->point; } } if(flag == cnt){ strcpy(tag[cnt++], p->tag_name[j]); tag_p[cnt - 1] += p->point; } flag = 0; } } //printf("cnt %d\n", cnt); } for(i = 0; i < cnt; i++){ p1 = &a[i]; p1->point = tag_p[i]; strcpy(p1->name, tag[i]); } qsort(tag_p, cnt, sizeof(int), func); for(i = 0; i < cnt;i++){ for(j = 0; j < cnt; j++){ if(flag2[j] == 0 && tag_p[i] == a[j].point){ b[i] = a[j]; //printf("i: %d %d\n", i, b[i].point); flag2[j] = 1; break; } } if(i > 0){ if(b[i - 1].point == b[i].point){ pre_flag3 = flag3; flag3++; //printf("i: %d flag3 %d %d %d\n", i, flag3, b[i - 1].point, b[i].point); }else if(flag3 > 0 && b[i - 1].point != b[i].point){ pre_flag3++; //printf("ok2 flag3 %d pre_flag3 %d\n", flag3, pre_flag3); } if(flag3 > 0 && flag3 - pre_flag3 == 0){ for(k = i - flag3; k < i; k++){ for(l = i - flag3; l < i; l++){ //printf("ok flag3 %d\n", flag3); if(strcmp(b[l - 1].name, b[l].name) > 0){ tmp = b[l - 1]; b[l - 1] = b[l]; b[l] = tmp; } } } flag3 = 0; pre_flag3 = 0; }else if(flag3 > 0 && i == cnt - 1){ for(k = i - flag3; k < i; k++){ for(l = i - flag3; l < i; l++){ //printf("okok\n"); if(strcmp(b[l - 1].name, b[l].name) > 0){ tmp = b[l - 1]; b[l - 1] = b[l]; b[l] = tmp; } } } } } } for(i = 0; i < 10; i++){ printf("%s %d\n", b[i].name, b[i].point); } return 0; }