# include <iostream>
using namespace std;
main(){
int n;
int g[101] = {0};
cout<<g[0]<<endl;
while(cin>>n && n!=0){
int grades,grade;
for(int i = 0;i<n;i++){
cin>>grades;
g[grades] = g[grades] + 1;
}
cin>>grade;
cout<<g[grade]<<endl;
}
}
# include <iostream>
# include <stdio.h>
# include <stdlib.h>
using namespace std;
int f[500001]={0};
int z[500001]={0};
main(){
int m,n;
while(cin>>n){
cin>>m;
for(int i=0;i<500000;i++){
f[i] = 0;
z[i] = 0;
}
int l;
for(int i=0;i<n;i++){
cin>>l;
int m1 = abs(l);
if(l>=0){
z[m1] = 1;
}else{
f[m1] = 1;
}
}
int k = 0;
for(int i = 500000;i>=0;i--){
if(z[i]==1){
k++;
cout<<i;
if(k>=m){
break;
}else{
cout<<" ";
}
}
}
if(k<m){
for(int i=1;i<=500000;i++){
if(f[i]==1){
cout<<"-"<<i;
k++;
if(k>=m){
break;
}else{
cout<<" ";
}
}
}
}
cout<<endl;
}
}
**注:**数组特别大的时候要定义成全局变量,因为如果定义在main方法里面使用的栈内存,会导致溢出。