题解 | #谁是你的潜在朋友#
谁是你的潜在朋友
https://www.nowcoder.com/practice/0177394fb25b42b48657bc2b1c6f9fcc
#include<iostream> #include<vector> #include<map> using namespace std; //习题10.6 谁是你的潜在朋友 int main() { int n, m; cin >> n >> m; vector<int> v; map<int, int> maps; for (int i = 0; i < n; i++) { int n; cin >> n; v.push_back(n); if (maps.find(n) == maps.end()) { maps[n] = 0; } maps[n] += 1; } for (auto it : v) { if (maps[it] > 1) { cout << maps[it] - 1 << endl; } else { cout << "BeiJu" << endl; } } return 0; }