栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

[PTA]病人排队(java)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[PTA]病人排队(java)

病人登记看病,编写一个程序,将登记的病人按照以下原则排出看病的先后顺序:

  1. 老年人(年龄 >= 60岁)比非老年人优先看病。
  2. 老年人按年龄从大到小的顺序看病,年龄相同的按登记的先后顺序排序。
  3. 非老年人按登记的先后顺序看病。
  4. import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Scanner;
    
    public class Day7 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n=Integer.parseInt(sc.nextLine());  //吸收换行
            List list1=new ArrayList<>();  //老年人放在一个集合中
            List list2=new ArrayList<>();  //非老年人放在一个集合中
            for(int j=1;j<=n;j++){
                String [] str=sc.nextLine().split(" ");
                int a=Integer.parseInt(str[1]);
                if(a>=60){
                    list1.add(new people(j,str[0],a));
                }
                else
                list2.add(new people(j,str[0],a));
            }
            Collections.sort(list1);
            for(int i=0;i {
        int no;
        String id;
        int age;
    
    
        public people(int no,String id, int age) {
            this.no=no;
            this.id = id;
            this.age = age;
        }
    
        @Override
        public int compareTo(people o) {
    
            if (this.age == o.age)
                    return this.no - o.no;
            else
                    return o.age - this.age;
    
            }
    
    
        }
    
    }
    

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/857977.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号