当前位置:编程学习 > JAVA >>

HDU1084

[java] 
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; 
    } www.zzzyk.com
 
    @Override 
    public int compareTo(Points o) { 
        if (pNum > o.pNum) 
            return -1; 
        if (pNum == o.pNum && time < o.time) 
            return -1; 
        return 1;&
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,