• map映射:书号→人数
#include<iostream>
#include<map>
using namespace std;

int main(){
  int n,m;
  int s[201];//输入数组
  while(scanf("%d",&n)!=EOF){
    scanf("%d",&m);
    map<int,int>reader;//书号→喜欢人数
    
    for(int i=0;i<n;i++){
      scanf("%d",&s[i]);
      reader[s[i]]++;
    }
    
    for(int i=0;i<n;i++){
      if(reader[s[i]]>1)printf("%d\n",reader[s[i]]-1);
      else printf("BeiJu\n");
    }
  }
   
  return 0;
}
  • 计数排序
#include<iostream>
using namespace std;
int s[201];
int reader[201];

int main(){
  int n,m;
  while(scanf("%d",&n)!=EOF){
    scanf("%d",&m);

    for(int i=0;i<n;i++){
      scanf("%d",&s[i]);
      reader[s[i]]++;
    }
    
    for(int i=0;i<n;i++){
      if(reader[s[i]]>1)printf("%d\n",reader[s[i]]-1);
      else printf("BeiJu\n");
    }
  }
   
  return 0;
}