文章
211
粉丝
1
获赞
1146
访问
40.2k
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
while(cin >> n >> m){
vector<int> likes(n + 1); // 下标从1到n,存储第i个读者喜欢的书的编号
// 用 map 统计每本书被多少读者喜欢
// key: 书号, value: 喜欢这本书的读者人数
unordered_map<int, int> bookCount;
for (int i = 1; i <= n; i++) {
cin >> likes[i];
bookCount[likes[i]]++; // 这本书的受欢迎度+1
}
for (int i = 1; i <= n; i++) {
int currentBook = likes[i]; // 当前读者i喜欢的书籍
// 潜在朋友数 = 喜欢这本书的总人数 - 1 (减去他自己)
int friends = bookCount[currentBook] - 1;
if (friends > 0) {
cout << friends << "\n";
} else {
// 如果没有人喜欢同一本书,输出 "BeiJu"
cout << "BeiJu" << "\n";
}
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发