#include <stdio.h> #include <string.h> #include <stdlib.h> #define N 55 #define M 105 typedef struct { int index; int count; }item; item items[M];
int cmp(const void *p, const void *q) { return (*(int *)p) - (*(int *)q); }
int cmp2(const void *p, const void *q) { item *a = (item *)p; item *b = (item *)q; if(a->count > b->count) return -1; else if(a->count < b->count) return 1; else { return a->index > b->index ? 1 : -1; } } int main() { int i, j, k; int size, quorum, dateNum, result, count, max; int dates[N][M]; int *find; while(scanf("%d%d", &size, &quorum) && size && quorum) { memset(dates, 0, sizeof(dates)); memset(items, 0, sizeof(items)); max = 0; for(i=0; i<size; i++) { scanf("%d", &dates[i][0]); for(j=1; j<=dates[i][0]; j++) { scanf("%d", &dates[i][j]); if(max < dates[i][j]) max = dates[i][j]; } }
for(i=1, k=0; i<=max; i++) { for(j=0, count=0; j<size; j++) { find = (int *)bsearch(&i, dates[j]+1, dates[j][0], sizeof(dates[j][1]), cmp); if(find != NULL) { count++; } } if(count >= quorum) { items[k].count = count; items[k].index = i; k++; } if(count == size) break; } qsort(items, k, sizeof(items[0]), cmp2); if(items[0].count >= quorum) printf("%d\n", items[0].index); else printf("0\n"); } return 0; }
|