AGE SORT

你有所有城市的人的年齡資料,而且這城市的人們都大於1歲,且都不會活超過100歲。現在你有個簡單的任務以升冪去排序所有的年齡

Input

接下來會有很多筆的資料,每筆資料從輸入n 開始 (0 < n < 2000000),n代表著城市全部的人數,

下一行將會有n個數代表著每個人的年齡,當輸入n=0時將會結束。

Ouput

每筆資料輸出一行n個數代表這城市所有的年齡而且以升冪排序,並且用空白分開。

Sample Input

5

3 4 2 1 5

6

2 3 2 3 1 7

0

Sample Output

1 2 3 4 5

1 2 2 3 3 7


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class AGE {
public static void main(String[] args) { Scanner scan = new Scanner(System.in);
int num;
int[] score = null;
List<Integer> result=new ArrayList<Integer>();
num = scan.nextInt(); while(num!=0){ score = new int[num];
for(int i=0;i<num;i++){
score[i]=scan.nextInt();
} sort(score); for(int i=0;i<score.length;i++){
result.add(score[i]);
} result.add(0);
num = scan.nextInt(); } playResult(result); } public static void sort(int[] score){
for (int i = 0; i < score.length -1; i++){
for(int j = 0 ;j < score.length - i - 1; j++){
if(score[j] > score[j + 1]){
int temp = score[j];
score[j] = score[j + 1];
score[j + 1] = temp;
}
}
} } public static void playResult(List<Integer> result ){
for(int i:result){
if(i!=0){
System.out.print(i+" ");
}else{
System.out.println();
}
}
} }

AGE SORT的更多相关文章

  1. Uva-------(11462) Age Sort(计数排序)

    B Age Sort Input: Standard Input Output: Standard Output   You are given the ages (in years) of all ...

  2. UVA 11462 Age Sort(计数排序法 优化输入输出)

    Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...

  3. 【输入输出挂】【Uva11462】Age Sort

    例题17  年龄排序(Age Sort, UVa 11462)照从小到大的顺序输出. [输入格式] 输入包含多组测试数据.每组数据的第一行为整数n(0<n≤2 000 000),即居民总数:下一 ...

  4. COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)

    ★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比时间限制:1 s   内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...

  5. ACM比赛(11462 Age Sort)

    You are given the ages (in years) of all people of a country with at least 1 year of age. You know t ...

  6. 【UVA 11462】 Age Sort(基数排序)

    题 题意 给你最多2000000个数据,大小是1到99的数,让你排序输出. 分析 快排也可以过.不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看 ...

  7. UVa 11462 Age Sort

    解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...

  8. 11462 Age Sort(计数排序)

    内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...

  9. 53. 特殊的O(n)时间排序[sort ages with hashtable]

    [本文链接] http://www.cnblogs.com/hellogiser/p/sort-ages-with-hashtable.html [题目] 某公司有几万名员工,请完成一个时间复杂度为O ...

  10. 剑指offer第32题:把数组排成最小的数及关于list.sort()和sorted( Iterable object )函数的相关知识

     * 解题思路:  * 先将整型数组转换成字符数组,然后将String数组排序,最后将排好序的字符串数组拼接出来.关键就是制定比较规则.  * 排序规则如下:  * 若ab > ba 则 a & ...

随机推荐

  1. Spring Boot Serverless 实战 | Serverless 应用的监控与调试

    ​简介:Spring Boot 是基于 Java Spring 框架的套件,它预装了 Spring 的一系列组件,让开发者只需要很少的配置就可以创建独立运行的应用程序.在云原生的环境中,有大量的平台可 ...

  2. 2019-9-19-dotnet-找不到-PostAsJsonAsync-方法

    title author date CreateTime categories dotnet 找不到 PostAsJsonAsync 方法 lindexi 2019-09-19 14:53:58 +0 ...

  3. IIS相关发布错误解决记录

    HRESULT 代码 0x80070021 错误消息: 应用程序"应用程序名称"中的服务器错误HTTP 错误 500.19 - 内部服务器错误HRESULT:0x80070021对 ...

  4. 如何将本地项目第一次同步到gitee远程

    一,Gitee账号的注册/登录 在gitee登录入口输入相关信息进行注册登录https://gitee.com/signup#lang=zh-CN 二,本地安装git客户端并配置用户信息 1.Git ...

  5. 【Android】Binder的Oneway拦截

    在某些虚拟化,免安装,打点,环境检测,拦截器等场景,针对Android系统服务接口的拦截是常用的技术方案.通常只是针对正向的接口调用,如果涉及被动的服务回调拦截,则实现起来就有些许麻烦. 说明 由于我 ...

  6. 9、iptables 防火墙

    1.iptables 基础规则 1.1.Linux 包过滤防火墙 netfilter 位于 Linux 内核中的包过滤功能体系 称为 Linux 防火墙的 "内核态" iptabl ...

  7. rails 上传文件

    控制器文件 app/controllers/api/v1/order_controller.rb def create # 从本地读取 log_dir = File.expand_path(File. ...

  8. 传统css布局方案(position,float,line-height等配合)

    一.display display 是 css 布局中很重要的一个属性,它定义了元素生成的显示框类型,常见的几个属性值有:block.inline.inline-block.inherit.none. ...

  9. AI 一键生成高清短视频,视频 UP 主们卷起来...

    现在短视频越来越火,据统计,2023年全球短视频用户数量已达 10 亿,预计到2027年将突破 24 亿.对于产品展示和用户营销来说,短视频已经成为重要阵地,不管你喜不喜欢它,你都得面对它,学会使用它 ...

  10. java学习之旅(day.17)

    GUI编程 GUI:图形用户界面编程 GUI快淘汰了 GUI的核心技术:Swing . AWT 这是类 做一个场景页面涉及的组件 窗口.弹窗.面板.文本框.列表框.按钮.图片.监听事件.鼠标.键盘.破 ...