题目
代码
网上别人
1 #include<iostream> 2 #include<vector> 3 4 using namespace std; 5 6 int main(){ 7 int n, m; 8 while(cin >> n >> m){ 9 // students[i] 表示第 i 个学生喜欢哪本书 10 vector<int> students(n, 0); 11 // books[i] 表示第 i 本书有几个学生喜欢 12 vector<int> books(m + 1, 0); 13 for(int i = 0; i < n; i ++){ 14 cin >> students[i]; 15 books[students[i]] ++; 16 } 17 for(int i = 0; i < n; i ++){ 18 int friends = books[students[i]] - 1; 19 if(friends > 0) cout << friends << endl; 20 else cout << "BeiJu" << endl; 21 } 22 } 23 return 0; 24 }
自己
1 #include<iostream> 2 #include<queue> 3 using namespace std; 4 int h[201]; 5 int main(){ 6 int n,m; 7 while(scanf("%d%d",&n,&m) != EOF){ 8 queue<int>q; 9 for(int i = 0;i < n;i++){ 10 int x; 11 scanf("%d" ,&x); 12 q.push(x); 13 h[x]++; 14 } 15 while(!q.empty()){ 16 int t = q.front();q.pop(); 17 if(h[t] > 1) printf("%d ",h[t]-1); 18 else printf("BeiJu "); 19 } 20 puts(""); 21 } 22 return 0; 23 }