数据结构实验之排序三:bucket sort
2017-12-18 18:58
204 查看
数据结构实验之排序三:bucket sort
根据人口普查结果,知道目前淄博市大约500万人口,你的任务是帮助人口普查办公室按年龄递增的顺序输出每个年龄有多少人,其中不满1周岁的按0岁计算,1到2周岁的按1岁计算,依次类推,大于等于100岁的老人全部按100岁计算。
输入第一行给出一个正整数N(<=5000000),随后连续给出N个整数表示每个人的年龄,数字间以空格分隔。
按年龄递增的顺序输出每个年龄的人口数,人口数为0的不输出,每个年龄占一行,数字间以一个空格分隔,行末不得有多余空格或空行。
Problem Description
根据人口普查结果,知道目前淄博市大约500万人口,你的任务是帮助人口普查办公室按年龄递增的顺序输出每个年龄有多少人,其中不满1周岁的按0岁计算,1到2周岁的按1岁计算,依次类推,大于等于100岁的老人全部按100岁计算。
Input
输入第一行给出一个正整数N(<=5000000),随后连续给出N个整数表示每个人的年龄,数字间以空格分隔。
Output
按年龄递增的顺序输出每个年龄的人口数,人口数为0的不输出,每个年龄占一行,数字间以一个空格分隔,行末不得有多余空格或空行。
Example Input
10 16 71 17 16 18 18 19 18 19 20
Example Output
16 2 17 1 18 3 19 2 20 1 71 1
#include<bits/stdc++.h> using namespace std ; int main(){ int n , m, a[101]; scanf("%d",&n); memset(a,0,sizeof(a)); for(int i=0; i<n; i++){ scanf("%d", &m); if(m>=100) a[100]++; else a[m]++; } for(int i=0; i<101; i++){ if(a[i] != 0) printf("%d %d\n",i,a[i]); } return 0 ; }
c++输入cin会消耗大量时间 引用 ios::。。。。。。。
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); int n, m, a[101]; cin>>n; memset(a, 0, sizeof(a)); for(int i=0; i<n; i++){ cin>>m; if(m>=100) a[100]++; else a[m]++; } for(int i=0; i<101; i++){ if(a[i]!=0) cout<<i<<" "<<a[i]<<endl; } return 0; }
相关文章推荐
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序七:选课名单
- 数据结构实验之排序七:选课名单
- 数据结构实验之排序七:选课名单
- 数据结构实验之排序一:一趟快排
- 数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和
- 数据结构实验之排序三:bucket sort 桶排序