C语言代码:统计点赞记录分析用户特性
#include <stdio.h> #include <stdlib.h> #include <string.h>
#define MAXN 1005 #define MAXK 15
int n, cnt[MAXN]; int *p[MAXN][MAXK];
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { int k; scanf("%d", &k); for (int j = 0; j < k; ++j) { p[i][j] = (int *)malloc(sizeof(int)); scanf("%d", p[i][j]); } qsort(p[i], k, sizeof(int *), cmp); }
int max = -1, maxIndex = -1;
for (int i = 0; i < n; ++i)
for (int j = 0; j < MAXK; ++j)
if (p[i][j] != NULL)
{
int k = *p[i][j];
++cnt[k];
if (cnt[k] > max || (cnt[k] == max && k > maxIndex))
{
max = cnt[k];
maxIndex = k;
}
free(p[i][j]);
}
printf("%d %d\n", maxIndex, max);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/oSbE 著作权归作者所有。请勿转载和采集!