洛谷 帮贡排序

洛谷 帮贡排序

题目链接

解题思路

题目描述内容过多,注意读懂,然后做几个排序即可。

代码描述

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s1="BangZhu";
		String s2="FuBangZhu";
		String s3="HuFa";
		String s4="ZhangLao";
		String s5="TangZhu";
		String s6="JingYing";
		String s7="BangZhong";
		int index=0;
		People[] sta=new People[3];
		
		People[] p=new People[n-3];
		String name;
		String identity;
		String tribute;
		int grade;
		for(int i=0;i<n;i++) {
			name=sc.next();
			identity=sc.next();
			tribute=sc.next();
			grade=sc.nextInt();
			
			if(i<3) {
				sta[index]=new People(name, identity, tribute, grade, i);
				index++;
			}
			else p[i-3]=new People(name, identity, tribute, grade, i);
		}
		Arrays.sort(p);
		//进行身份转换
		ArrayList<People>[] arr=new ArrayList[5];
		for(int i=0;i<5;i++) {
			arr[i]=new ArrayList<Main.People>();
		}
		index=1;
		for(int i=0;i<n-3;i++) {
			if(index<=2) {
				p[i].identity=s3;
				arr[0].add(p[i]);
			}
			else if(index<=6) {
				p[i].identity=s4;
				arr[1].add(p[i]);
			}
			else if(index<=13) {
				p[i].identity=s5;
				arr[2].add(p[i]);
			}
			else if(index<=38) {
				p[i].identity=s6;
				arr[3].add(p[i]);
			}
			else {
				p[i].identity=s7;
				arr[4].add(p[i]);
			}
			index++;
		}
		for(int i=0;i<5;i++) {
			Collections.sort(arr[i],new Comparator<People>() {
				public int compare(People o1,People o2) {
					//等级排序
					if(o1.grade!=o2.grade) return o2.grade-o1.grade;
					//经验排序
					return o1.Id-o2.Id;
				}
			});
		}
		
		//开始进行输出
		for(int i=0;i<3;i++) {
			System.out.println(sta[i].name+" "+sta[i].identity+" "+sta[i].grade);
		}
		for(int i=0;i<5;i++) {
			for(People p1:arr[i]) {
				System.out.println(p1.name+" "+p1.identity+" "+p1.grade);
			}
		}
		return;
	}
	static public class People implements Comparable<People>{
		People(String name,String identity,String tribute,int grade,int id){
			this.name=name;
			this.identity=identity;
			this.tribute=tribute;
			this.grade=grade;
			this.Id=id;
		}
		public String name;
		public String identity;
		public String tribute;
		public int grade;
		public int Id;
		@Override
		public int compareTo(People o2) {
			//帮贡 从大到小
			if(this.tribute.length()-o2.tribute.length()!=0) {
				return o2.tribute.length()-this.tribute.length();
			}
			return -this.tribute.compareTo(o2.tribute);
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值