此题限时,如果用的c++的话,用cin输入相对于scanf会消耗更多的时间,消除的方式是在main()函数开始的时候加上一句 ios::sync_with_stdio(false); 这样可以使cin和scanf的效率相差甚小。
如果用c则木有这个问题
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int num1,num2;
int main()
{
ios::sync_with_stdio(false);
int n,x;
cin>>n;
int a[101] = {0};
while(n--){
cin>>x;
if(x>100)//再一点需要注意的就是大于100岁,按100岁来算
x = 100;
a[x]++;
}
for(int i=0; i<=100; i++){
if(a[i])
cout<<i<<" "<<a[i]<<endl;
}
return 0;
}