题解 | #谁是你的潜在朋友#map的使用

谁是你的潜在朋友

https://www.nowcoder.com/practice/0177394fb25b42b48657bc2b1c6f9fcc

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

int stu[205];

int main() {
    int n, m; //n个人 m本书
    map<int, int> mymap; //<booknum, totallove>
    while (scanf("%d%d", &n, &m) != EOF) {
        for (int i = 0; i < n; i++) {
            int t;
            scanf("%d", &t);
            stu[i] = t; //第i个人,喜欢第t本书
            if (mymap.find(t) != mymap.end()) { //有人喜欢这本书
                mymap[t]++;
            } else {
                mymap[t] = 1;
            }
        }

        for (int i = 0; i < n; i++) {
            int t = stu[i];
            if (mymap[t] != 1) { //有人喜欢这本书              
                printf("%d\n", mymap[t] - 1);
            } else {
                printf("BeiJu\n");
            }
        }
    }
}

全部评论

相关推荐

07-09 18:33
门头沟学院 Java
这么逆天每年都有人去???&nbsp;填多益网申就是大型的服从性测试
鲁大牛:辅导员在群里发了这个公司我就申了一下。网申居然要写当场开摄像头写两篇不少于三百字的作文。太逆天了
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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