题解 | #谁是你的潜在朋友#
谁是你的潜在朋友
https://www.nowcoder.com/practice/0177394fb25b42b48657bc2b1c6f9fcc
#include<iostream> #include<vector> int main() { int n, m; int book[201]; std::vector<int> v; while (std::cin >> n >> m) { std::fill(book, book+201, 0); v.reserve(n); int a; for (int i = 0; i < n; i++) { std::cin >> a; book[a]++;//使用标记数组,对带有相同图书编号的自动加1 v.push_back(a);//记录输入图书编号的顺序 } for(int i : v) { if(book[i] > 1) std::cout << book[i]-1 << std::endl; else std::cout << "BeiJu" << std::endl; } } }