题意给定 N 个读者各自喜欢的书号,对每个读者输出「潜在朋友」数,即喜欢同一本书的其他读者人数;没有同伴则输出 BeiJu。
思路
先统计每本书被多少人喜欢 cnt[p],读者的答案就是 cnt[p] - 1。答案大于 0 输出数值,等于 0 输出 BeiJu。
复杂度O(N + M)。
参考代码(C / C++ / Java / Python)
C:
#include <stdio.h>
int b[100005], cnt[100005];
int main(){
int n, m, i;
while(scanf("%d %d", &n, &...