HDU1084

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084

package D0709;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class HDU1084 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n;
		while (sc.hasNext()) {
			n = sc.nextInt();
			if (n < 0)
				break;
			//集合保存所有学生的成绩
			ArrayList<Points> list = new ArrayList<Points>();
			int id=0;//为每一个学生添加一列id以方便得到本来输入的时候的顺序
			for (int i = 0; i < n; i++) {
				int pNum = sc.nextInt();//解决的题目数量
				String str = sc.next();
				String[] ss = str.split("\\:");
				//所用时间
				int time = Integer.parseInt(ss[0]) * 3600 + Integer.parseInt(ss[1]) * 60 + Integer.parseInt(ss[2]);
				int score = 50 + pNum*10;
				//添加一个学生到集合
				list.add(new Points(++id,pNum,time,score));
			}
			// 排序
			Collections.sort(list);
			//分数操作
			for(int i = 0;i<list.size();){
				Points pts = list.get(i);
				int count = 1;
				for(int j = i+1;j<list.size();j++){
					Points pts2 = list.get(j);
					if(pts.pNum == pts2.pNum){
						count ++;
					}else break;
				}
				// 有多个学生做出的题数相同(大于0小于5)
				if(count > 1&& list.get(i).pNum < 5 && list.get(i).pNum>0){
					for(int k = 0;k<count/2;k++){
						list.get(i+k).score+=5;
					}
				}
				//只有一个学生做出这么多(x)题(大于0小于5)
				if (count == 1 && list.get(i).pNum < 5 && list.get(i).pNum>0)
					list.get(i).score += 5;
				i += count;//继续循环
			}
			int[]score = new int[n+1];// 用来按照输入顺序记录学生的最后分数
			for(int i = 0;i<list.size();i++){
				score[list.get(i).id] =list.get(i).score; 
			}
			//输出
			for (int i = 1;i<=n;i++) {
				System.out.println(score[i]);
			}
			System.out.println();
		}
	}
}

class Points implements Comparable<Points> {
	public int id;
	public int pNum;
	public int time;
	public int score;

	public Points(int id,int pNum, int time, int score) {
		this.id = id;
		this.pNum = pNum;
		this.time = time;
		this.score = score;
	}

	@Override
	public int compareTo(Points o) {
		if (pNum > o.pNum)
			return -1;
		if (pNum == o.pNum && time < o.time)
			return -1;
		return 1;
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怎么演

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值