谁是你的潜在朋友

谁是你的潜在朋友

http://www.nowcoder.com/questionTerminal/0177394fb25b42b48657bc2b1c6f9fcc

思路

其实就是存一下每个人喜欢哪一本书,然后每本书对应有几个人喜欢就好了,潜在朋友就是喜欢这本书的人数减一。

#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m){
        // students[i] 表示第 i 个学生喜欢哪本书
        vector<int> students(n, 0);
        // books[i] 表示第 i 本书有几个学生喜欢
        vector<int> books(m + 1, 0);
        for(int i = 0; i < n; i ++){
            cin >> students[i];
            books[students[i]] ++;
        }
        for(int i = 0; i < n; i ++){
            int friends = books[students[i]] - 1;
            if(friends > 0) cout << friends << endl;
            else cout << "BeiJu" << endl;
        }
    }
    return 0;
}
算法题解 文章被收录于专栏

不定期更新一些算法题解,有什么问题可以随时留言~

全部评论

相关推荐

昨天 13:16
湖南工学院 Java
点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务