数据结构实验之排序三:bucket sort
来源:互联网 发布:歌曲剪切合并软件 编辑:程序博客网 时间:2024/06/06 01:41
数据结构实验之排序三:bucket sort
Time Limit: 250MS Memory Limit: 65536KB
Submit Statistic
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
Hint
Author
xam
#include <iostream>#include <string>#include <cstring>#include <stdio.h>using namespace std;const int MAX = 100005;void bucketSort(int n){ //int a[105]; //memset(a, 0, sizeof(a)); int *a = new int[105](); int i; int t; for (i = 0; i < n; i++) { scanf("%d", &t); if (t > 100) t = 100; a[t]++; } for (i = 0; i < 105; i++) { if (a[i] != 0) { printf("%d %d\n", i, a[i]); } }}int main(){ int n; scanf("%d", &n); bucketSort(n); return 0;}
阅读全文
0 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
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 数据结构实验之排序三:bucket sort
- 【笔记】深入理解 java 虚拟机---垃圾收集器
- 猜拳小游戏
- table-table-layout和border-collapse: collapse的用法
- Ubuntu安装桌面程序
- layUI中点击按钮选择图片(不自动上传),然后点击上传按钮,上传图片(可以上传多个文件)
- 数据结构实验之排序三:bucket sort
- Unity 扇形UI 360Canvas
- 五大常用算法之一:分治法
- dubbo注入service服务,运行加载报错:Error creating bean with name........
- 123
- Excel导出文件名乱码问题
- 安装虚拟机增强工具vmware tool
- Android绘图机制二
- ListPopupWindow宽度自适应